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

            Bug ID: 83393
           Summary: [8 Regression] wrong code with -O2
                    -fno-forward-propagate -fno-tree-bit-ccp
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zsojka at seznam dot cz
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu
            Target: x86_64-pc-linux-gnu

Created attachment 42848
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42848&action=edit
reduced testcase

Output:
$ x86_64-pc-linux-gnu-gcc -O2 -fno-forward-propagate -fno-tree-bit-ccp
testcase.c
$ ./a.out 
Aborted

$ x86_64-pc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-amd64/bin/x86_64-pc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-255576-checking-yes-rtl-df-extra-nographite-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/8.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++
--enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra
--without-cloog --without-ppl --without-isl --build=x86_64-pc-linux-gnu
--host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu
--with-ld=/usr/bin/x86_64-pc-linux-gnu-ld
--with-as=/usr/bin/x86_64-pc-linux-gnu-as --disable-libstdcxx-pch
--prefix=/repo/gcc-trunk//binary-trunk-255576-checking-yes-rtl-df-extra-nographite-amd64
Thread model: posix
gcc version 8.0.0 20171212 (experimental) (GCC) 

Tested revisions:
trunk r255576 - FAIL
trunk r255386 - FAIL

.combine shows:

insn_cost 4 for     8: r111:SI=[`d']
insn_cost 4 for     9: r112:HI=r111:SI#0
      REG_DEAD r111:SI
insn_cost 4 for    11: {r114:HI=r112:HI<<0xf;clobber flags:CC;}
      REG_DEAD r112:HI
      REG_UNUSED flags:CC
insn_cost 6 for    14: {r108:HI=r114:HI-0x23;clobber flags:CC;}
      REG_DEAD r114:HI
      REG_UNUSED flags:CC
insn_cost 4 for    15: r115:SI=zero_extend(r108:HI)
insn_cost 4 for    16: flags:CC=cmp(r108:HI,0x23)
      REG_DEAD r108:HI
insn_cost 4 for    17: r117:QI=leu(flags:CC,0)
      REG_DEAD flags:CC
insn_cost 4 for    18: r116:SI=zero_extend(r117:QI)
      REG_DEAD r117:QI
insn_cost 4 for    19: {r93:SI=r115:SI<<r116:SI#0;clobber flags:CC;}
      REG_DEAD r116:SI
      REG_DEAD r115:SI
      REG_UNUSED flags:CC
insn_cost 4 for    20: r108:HI=r93:SI#0



Trying 8 -> 9:
...
deferring deletion of insn with uid = 8.
modifying insn i3     9: r112:HI=[`d']
deferring rescan insn with uid = 9.


Trying 19 -> 20:
...
deferring deletion of insn with uid = 19.
modifying insn i3    20: {r108:HI=r115:SI#0<<r116:SI#0;clobber flags:CC;}
      REG_UNUSED flags:CC
      REG_DEAD r115:SI
      REG_DEAD r116:SI
deferring rescan insn with uid = 20.


Trying 15 -> 20:
   15: r115:SI=zero_extend(r108:HI)
   20: {r108:HI=r115:SI#0<<r116:SI#0;clobber flags:CC;}
      REG_UNUSED flags:CC
      REG_DEAD r115:SI
      REG_DEAD r116:SI
Successfully matched this instruction:
(parallel [
        (set (reg/v:HI 108 [ fD.1899 ])
            (ashift:HI (reg/v:HI 108 [ fD.1899 ])
                (subreg:QI (reg:SI 116) 0)))
        (clobber (reg:CC 17 flags))
    ])
allowing combination of insns 15 and 20
original costs 4 + 4 = 8
replacement cost 4
deferring deletion of insn with uid = 15.
modifying insn i3    20: {r108:HI=r108:HI<<r116:SI#0;clobber flags:CC;}
      REG_DEAD r116:SI
      REG_UNUSED flags:CC
deferring rescan insn with uid = 20.


Trying 14, 16 -> 18:
   14: {r108:HI=r114:HI-0x23;clobber flags:CC;}
      REG_DEAD r114:HI
      REG_UNUSED flags:CC
   16: flags:CC=cmp(r108:HI,0x23)
      REG_DEAD r108:HI
   18: r116:SI=leu(flags:CC,0)
      REG_DEAD flags:CC
Successfully matched this instruction:
(set (reg:SI 116)
    (const_int 0 [0]))
allowing combination of insns 14, 16 and 18
original costs 6 + 4 + 4 = 14
replacement cost 4
deferring deletion of insn with uid = 16.
deferring deletion of insn with uid = 14.
deferring deletion of insn with uid = 9.
deferring deletion of insn with uid = 11.
modifying insn i3    18: r116:SI=0
deferring rescan insn with uid = 18.


It seems insns 9, 11, 14, 16 get deleted, even though insn 16 output (r108)
should be used insn 20; it is likely I overlooked something though. I don't
know if r108 reuse (insn 14 sets; insn 16 dead; insn 20 sets again) might be
related to this.

Reply via email to