When compiling this code with clang 3.9:
constexpr bool is_small(long long v) {
return v < 0x4000000000000000;
}
int foo();
int f(int a) {
if (is_small(a)) return a;
else return foo();
}
it produces an assembly equivalent int f(int a) { return a; }, since it determined that is_small(a)it will always be true, as it ais int, which (on my platform) is always smaller 0x4000000000000000.
When I change is_smallto:
constexpr bool is_small(long long v) {
return v >= -0x4000000000000000;
}
the same thing happens as expected.
However, when I change is_smallto check both conditions:
constexpr bool is_small(long long v) {
return v < 0x4000000000000000 && v >= -0x4000000000000000;
}
clang does not optimize part ifand return foo().
(Here are the above snippets on Godbolt to play with: https://godbolt.org/g/fnoE9A )
Why is this happening? He clearly concluded that conditions are individually always true, why does this not apply to the logical connection of both?