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

            Bug ID: 79910
           Summary: [7 Regression] wrong code with -O -fweb
           Product: gcc
           Version: 7.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 40892
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40892&action=edit
reduced testcase

Output:
$ x86_64-pc-linux-gnu-gcc -O -fweb 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-245841-checking-yes-rtl-df-extra-nographite-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/7.0.1/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-245841-checking-yes-rtl-df-extra-nographite-amd64
Thread model: posix
gcc version 7.0.1 20170302 (experimental) (GCC) 


There seems to be a problem in the combine pass.
Before .combine, there is:
...
(insn 16 14 17 2 (parallel [
            (set (reg/v:DI 100 [ bD.1802 ])
                (lshiftrt:DI (reg:DI 107)
                    (reg:QI 110)))
            (clobber (reg:CC 17 flags))
        ]) "testcase.c":11 544 {*lshrdi3_1}
     (expr_list:REG_DEAD (reg:QI 110)
        (expr_list:REG_DEAD (reg:DI 107)
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))
...
(insn 28 27 30 2 (parallel [
            (set (reg:DI 128 [ _6 ])
                (minus:DI (reg:DI 111 [ p1D.1798 ])
                    (reg:DI 119)))
            (clobber (reg:CC 17 flags))
        ]) "testcase.c":12 272 {*subdi_1}
     (expr_list:REG_DEAD (reg:DI 119)
        (expr_list:REG_DEAD (reg:DI 111 [ p1D.1798 ])
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))
(insn 30 28 31 2 (parallel [
            (set (reg:SI 120)
                (and:SI (subreg:SI (reg/v:DI 100 [ bD.1802 ]) 0)
                    (const_int 31 [0x1f])))
            (clobber (reg:CC 17 flags))
        ]) "testcase.c":13 389 {*andsi_1}
     (expr_list:REG_UNUSED (reg:CC 17 flags)
        (nil)))
(insn 31 30 32 2 (set (reg:SI 121)
        (const_int 4 [0x4])) "testcase.c":13 82 {*movsi_internal}
     (nil))
(insn 32 31 33 2 (parallel [
            (set (reg/v:SI 106 [ p2D.1799 ])
                (lshiftrt:SI (reg:SI 121)
                    (subreg:QI (reg:SI 120) 0)))
            (clobber (reg:CC 17 flags))
        ]) "testcase.c":13 542 {*lshrsi3_1}
     (expr_list:REG_DEAD (reg:SI 121)
        (expr_list:REG_DEAD (reg:SI 120)
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (expr_list:REG_EQUAL (lshiftrt:SI (const_int 4 [0x4])
                        (subreg:QI (reg:SI 120) 0))
                    (nil))))))
...


But .combine shows:

...
Trying 27, 28 -> 33:
...
Successfully matched this instruction:
(set (reg:QI 128 [ _6 ])
    (plus:QI (subreg:QI (reg:DI 111 [ p1D.1798 ]) 0)
        (subreg:QI (reg/v:DI 100 [ bD.1802 ]) 0)))
Successfully matched this instruction:
(set (reg:QI 123 [ p1D.1798 ])
    (plus:QI (reg:QI 128 [ _6 ])
        (subreg:QI (reg:DI 92 [ _6 ]) 0)))
allowing combination of insns 27, 28 and 33
...
Trying 16, 32 -> 35:
...
Successfully matched this instruction:
(set (reg/v:DI 100 [ bD.1802 ])
    (lshiftrt:DI (reg:DI 107)
        (reg:QI 110)))
Successfully matched this instruction:
(set (reg:SI 125 [ p2D.1799 ])
    (const_int 0 [0]))
allowing combination of insns 16, 32 and 35
...

So after .combine, there is:
...
(insn 28 27 30 2 (parallel [
            (set (reg:QI 128 [ _6 ])
                (plus:QI (subreg:QI (reg:DI 111 [ p1D.1798 ]) 0)
                    (subreg:QI (reg/v:DI 100 [ bD.1802 ]) 0)))
            (clobber (reg:CC 17 flags))
        ]) "testcase.c":12 219 {*addqi_1}
     (expr_list:REG_UNUSED (reg:CC 17 flags)
        (expr_list:REG_DEAD (reg:DI 111 [ p1D.1798 ])
            (nil))))
(note 30 28 31 2 NOTE_INSN_DELETED)
(note 31 30 32 2 NOTE_INSN_DELETED)
(insn 32 31 33 2 (parallel [
            (set (reg/v:DI 100 [ bD.1802 ])
                (lshiftrt:DI (reg:DI 107)
                    (reg:QI 110)))
            (clobber (reg:CC 17 flags))
        ]) "testcase.c":13 544 {*lshrdi3_1}
     (expr_list:REG_UNUSED (reg:CC 17 flags)
        (expr_list:REG_DEAD (reg:DI 107)
            (expr_list:REG_DEAD (reg:QI 110)
                (nil)))))
...

--> reg 100 is used in insn 28 before it is set in insn 32.

Reply via email to