[Bug tree-optimization/103986] New: Miscompilation with -O2 -funswitch-loops and __builtin_unreachable in ternary operator

daniel at constexpr dot org gcc-bugzilla@gcc.gnu.org
Wed Jan 12 03:38:15 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103986

            Bug ID: 103986
           Summary: Miscompilation with -O2 -funswitch-loops and
                    __builtin_unreachable in ternary operator
           Product: gcc
           Version: 10.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daniel at constexpr dot org
  Target Milestone: ---

Created attachment 52166
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52166&action=edit
Reduced test case

The loop in the attached reduced test case does not terminate when compiled
with -O3 or -O2 -funswitch-loops with GCC 9.4.0 or GCC 10.3.1 even though it
should only iterate 144 times.

Curiously, the programs works as expected when using an if() instead of the
ternary operator in the assume macro but maybe that's just luck.

I could not reproduce the issue with GCC 8.5.0, GCC 11.2.1 or my GCC 12
checkout from 20220102.


More information about the Gcc-bugs mailing list