[llvm-bugs] [Bug 35336] New: OpenPOWER: Evaluate branch before storing values

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Nov 16 16:13:36 PST 2017


https://bugs.llvm.org/show_bug.cgi?id=35336

            Bug ID: 35336
           Summary: OpenPOWER: Evaluate branch before storing values
           Product: clang
           Version: 3.6
          Hardware: PC
                OS: Linux
            Status: NEW
          Keywords: code-quality, performance
          Severity: enhancement
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: sbiersdorff at nvidia.com
                CC: eric.schweitz at pgroup.com, llvm-bugs at lists.llvm.org

Created attachment 19434
  --> https://bugs.llvm.org/attachment.cgi?id=19434&action=edit
Example code showing performance issue

Consider the attached code. On entry to the ‘quick_return’ function a check is
made whether to return immediately. Hopefully if this flag is true this
function returns quickly--executing only a minimal number of instructions.
However, compare Clang generated instruction verses GNU generated code:

Clang:

0000000010000630 <quick_return>:
    10000630:   02 10 40 3c     lis     r2,4098
    10000634:   00 8c 42 38     addi    r2,r2,-29696
    10000638:   a6 02 08 7c     mflr    r0
    1000063c:   f8 ff e1 fb     std     r31,-8(r1)
    10000640:   10 00 01 f8     std     r0,16(r1)
    10000644:   91 ff 21 f8     stdu    r1,-112(r1)
    10000648:   78 0b 3f 7c     mr      r31,r1
    1000064c:   00 00 03 28     cmplwi  r3,0
    10000650:   60 00 df fb     std     r30,96(r31)
    10000654:   78 23 9e 7c     mr      r30,r4
    10000658:   50 00 82 40     bne     100006a8 <quick_return+0x78>

GNU:

00000000100007c0 <quick_return>:
    100007c0:   02 10 40 3c     lis     r2,4098
    100007c4:   00 7f 42 38     addi    r2,r2,32512
    100007c8:   00 00 a3 2f     cmpdi   cr7,r3,0
    100007cc:   20 00 9e 4c     bnelr   cr7

Notice the three ‘store’ instruction generated by Clang before the branch is
evaluated. An improvement would be generating code more similar to GNU placing
these ‘store’ instruction after the check to see if the function should return
immediately.

Note these examples both used the flag ‘-O3’.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171117/cb7ea63b/attachment.html>


More information about the llvm-bugs mailing list