This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug rtl-optimization/47764] The constant load instruction should be hoisted out of loop


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

--- Comment #6 from Carrot <carrot at google dot com> ---
Another example for ppc. 
Following code is disassembled from sha1dgst.o in openssl which is compiled by
gcc

0000000000000000 <sha1_block_data_order>:
      ...
      80:       82 5a 52 3f     addis   r26,r18,23170
      84:       78 9a 4a 7e     xor     r10,r18,r19
      88:       08 00 c4 8a     lbz     r22,8(r4)
      8c:       88 00 1f ea     ld      r16,136(r31)
      90:       0b 00 a4 8b     lbz     r29,11(r4)
      94:       02 00 c4 8b     lbz     r30,2(r4)
      98:       99 79 5a 3b     addi    r26,r26,31129
      ...

it uses two instructions to do (r18 + 23170 << 16 + 31129), this large constant
is used many times. In following command line sha1.gcc is disassembled from
sha1dgst.o.

$ grep 31129 sha1.gcc | wc
     20     140     881
$ grep 23170 sha1.gcc | wc
     20     140     886

If we load this large constant into a register, and use this register later, we
can save 18 instructions.

There are more such cases in the same functions:

$ grep 28378 sha1.gcc | wc
     20     140     875
$ grep "\-5215" sha1.gcc | wc
     20     140     867
$ grep "\-28900" sha1.gcc | wc
     20     140     915
$ grep "\-17188" sha1.gcc | wc
     20     140     916
$ grep "\-13725" sha1.gcc | wc
     20     140     915
$ grep "\-15914" sha1.gcc | wc
     20     140     914

More worse, these codes are inside a hot loop.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]