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

            Bug ID: 88971
           Summary: Branch optimization inconsistency (missed
                    optimization)
           Product: gcc
           Version: 8.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: maratrus at mail dot ru
  Target Milestone: ---

Created attachment 45490
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45490&action=edit
A code that demonstrates different patterns in optimization technique

In the code attached I expect the compiler not to generate any code between two
`mfence` instructions in the method `CheckAndPrint()`.

Indeed, it does the good job if I call `PrintGood<false>()` method and no code
is generated. But if I out-comment `PrintBad<false>()` or even simple return
the compiler generates a code for the if-expression `if (t.j > 0)`.

In all three cases there seems to be no reason to generate any code.

The code attached is compiled as:

`g++ -std=c++11 -Ofast opt_template.cc -o opt_template`

I must be missing something but is there a good reason why the compiler managed
to optimize the code in one case but non in the other two?

Reply via email to