http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56309



             Bug #: 56309

           Summary: -O3 optimizer generates conditional moves instead of

                    compare and branch resulting in almost 2x slower code

    Classification: Unclassified

           Product: gcc

           Version: 4.7.2

            Status: UNCONFIRMED

          Severity: normal

          Priority: P3

         Component: middle-end

        AssignedTo: unassig...@gcc.gnu.org

        ReportedBy: arturo...@gmail.com





Created attachment 29442

  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29442

Self contained source file with parameter x passed by value (slow)



This bug report reflects the analysis of a question asked in stackoverflow



http://stackoverflow.com/questions/14805641/why-does-changing-const-ull-to-const-ull-in-function-parameter-result-in-pe/14819939#14819939



When an unsigned long long parameter to a function is passed by reference

instead of by value the result is a dramatic almost 2x improvement in speed

when compiled with -O3.  Given that the function is inlined this is unexpected.

 Upon closer inspection it was found that the code generated is quite

different, as if passing the parameter by value enables an optimization (use of

x86 conditional moves) that backfires, possibly by suffering an unexpected

stall in the processor.



Two files are attached



by-val-O3.ii

by-ref-O3.ii



They differ only in the way the unsigned long long parameter "x" is passed.



./by-ref-O3

Took 11.85 seconds total.



./by-ref-O3

Took 6.67 seconds total.

Reply via email to