https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93939
Bug ID: 93939 Summary: missing optimization for floating-point expression converted to integer whose result is known at compile time Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: vincent-gcc at vinc17 dot net Target Milestone: --- Consider the following example. #include <stdio.h> typedef double T; int main (void) { volatile T a = 8; T b = a; int i; i = 3 * b; printf ("%d\n", (int) i); if (b == 8) { i = 3 * b; printf ("%d\n", i == 24); } return 0; } Even if one compiles it with -O3, a comparison instruction for i == 24 is generated, while its result 1 is known at compile time. If I change T to int, or change the type of i to double, or comment out the first printf (so that the first i is not used), then the i == 24 is optimized as expected. Tested under Debian/unstable / x86_64 with: gcc-10 (Debian 10-20200222-1) 10.0.1 20200222 (experimental) [master revision 01af7e0a0c2:487fe13f218:e99b18cf7101f205bfdd9f0f29ed51caaec52779]