http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56598
Bug #: 56598 Summary: Optimizer can't invert conditional when inlining a bool function Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: minor Priority: P3 Component: rtl-optimization AssignedTo: unassig...@gcc.gnu.org ReportedBy: msha...@users.sourceforge.net Created attachment 29640 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29640 Simple test case and its asm When a bool macro like #define X(i) (i==3) is replaced with a static inline bool function, the optimizer sometimes generates tangled control flow. With code blocks ABCD the jumps go A->C->B->D. If the macro is used, the compiler can invert the conditional and emit ACBD with two fewer jmps. In the attached test case, func1 has .L3-.L4 block that is jumped into, out of, and over. Swapping the .L2-.L3 and .L3-.L4 blocks would produce the simpler control flow in func2. The test case is compiled with -Os, on x86_64. -O2 and -O3 also produce the same behavior, but require a larger test case to avoid path unrolling. C++ compiler must be used. The same test case compiled as C produces identical func1 and func2.