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

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The first weird thing is the cse_local pass.
Before that it seems we compute twice
11 / -2 + 4 + (11 / -2 + 4U <= 2U ? 11 / -2 + 3 : 0)
which is that in GIMPLE simplified (1 / c + (g - 1)) with f = -2 propagated
into it.
(insn 15 13 24 3 (set (reg/v:SI 130 [ f ])
        (const_int -2 [0xfffffffffffffffe])) "pr121675.c":6:5 100
{*movsi_internal}
     (nil))
(insn 24 15 26 3 (parallel [
            (set (reg:SI 133 [ _30 ])
                (div:SI (const_int 11 [0xb])
                    (reg/v:SI 130 [ f ])))
            (set (reg:SI 134)
                (mod:SI (const_int 11 [0xb])
                    (reg/v:SI 130 [ f ])))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":9:10 681 {*divmodsi4_const}
     (expr_list:REG_DEAD (reg:SI 135)
        (expr_list:REG_DEAD (reg:SI 115 [ f.4_29 ])
            (expr_list:REG_UNUSED (reg:SI 134)
                (expr_list:REG_UNUSED (reg:CC 17 flags)
                    (nil))))))
(insn 26 24 27 3 (parallel [
            (set (reg:SI 136 [ _32 ])
                (plus:SI (reg:SI 133 [ _30 ])
                    (const_int 3 [0x3])))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":9:18 287 {*addsi_1}
     (expr_list:REG_UNUSED (reg:CC 17 flags)
        (nil)))
(insn 27 26 29 3 (parallel [
            (set (reg:SI 137 [ _78 ])
                (plus:SI (reg:SI 133 [ _30 ])
                    (const_int 4 [0x4])))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":11:11 287 {*addsi_1}
     (expr_list:REG_UNUSED (reg:CC 17 flags)
        (nil)))
(insn 29 27 28 3 (set (reg:SI 138)
        (const_int 0 [0])) "pr121675.c":11:11 100 {*movsi_internal}
     (nil))
(insn 28 29 30 3 (set (reg:CC 17 flags)
        (compare:CC (reg:SI 137 [ _78 ])
            (const_int 2 [0x2]))) "pr121675.c":11:11 15 {*cmpsi_1}
     (expr_list:REG_DEAD (reg:SI 137 [ _78 ])
        (nil)))
(insn 30 28 32 3 (set (reg:SI 136 [ _32 ])
        (if_then_else:SI (leu (reg:CC 17 flags)
                (const_int 0 [0]))
            (reg:SI 136 [ _32 ])
            (reg:SI 138))) "pr121675.c":11:11 1810 {*movsicc_noc}
     (expr_list:REG_EQUAL (if_then_else:SI (leu (reg:CC 17 flags)
                (const_int 0 [0]))
            (reg:SI 136 [ _32 ])
            (const_int 0 [0]))
        (expr_list:REG_DEAD (reg:SI 138)
            (expr_list:REG_DEAD (reg:CC 17 flags)
                (nil)))))
(insn 32 30 33 3 (parallel [
            (set (reg:SI 140 [ _35 ])
                (plus:SI (reg:SI 136 [ _32 ])
                    (reg:SI 137 [ _78 ])))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":11:15 287 {*addsi_1}
     (expr_list:REG_DEAD (reg:SI 139 [ _34 ])
        (expr_list:REG_DEAD (reg:SI 136 [ _32 ])
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))
So, r140 is the whole expression, r136 is the ?: part, r137 11 / -2 + 4 part.
But cse_local turns that into:
(insn 15 13 24 3 (set (reg/v:SI 130 [ f ])
        (const_int -2 [0xfffffffffffffffe])) "pr121675.c":6:5 100
{*movsi_internal}
     (nil))
(insn 24 15 27 3 (parallel [
            (set (reg:SI 133 [ _30 ])
                (div:SI (const_int 11 [0xb])
                    (reg/v:SI 130 [ f ])))
            (set (reg:SI 134)
                (mod:SI (const_int 11 [0xb])
                    (reg/v:SI 130 [ f ])))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":9:10 681 {*divmodsi4_const}
     (expr_list:REG_DEAD (reg/v:SI 130 [ f ])
        (expr_list:REG_UNUSED (reg:SI 134)
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))
(insn 27 24 29 3 (set (reg:SI 137 [ _78 ])
        (const_int -1 [0xffffffffffffffff])) "pr121675.c":11:11 100
{*movsi_internal}
     (expr_list:REG_DEAD (reg:SI 133 [ _30 ])
        (expr_list:REG_UNUSED (reg:CC 17 flags)
            (nil))))
(insn 29 27 28 3 (set (reg:SI 138)
        (const_int 0 [0])) "pr121675.c":11:11 100 {*movsi_internal}
     (nil))
(insn 28 29 32 3 (set (reg:CC 17 flags)
        (compare:CC (reg:SI 137 [ _78 ])
            (const_int 2 [0x2]))) "pr121675.c":11:11 15 {*cmpsi_1}
     (nil))
(insn 32 28 33 3 (parallel [
            (set (reg:SI 140 [ _35 ])
                (minus:SI (reg:SI 138)
                    (reg:SI 134)))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":11:15 393 {*subsi_1}
     (expr_list:REG_DEAD (reg:SI 137 [ _78 ])
        (expr_list:REG_DEAD (reg:SI 136 [ _32 ])
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))
r137 is right, 11 / -2 + 4 is -1.  But the change of r140 from the addition to
0 - (11 % -2) is just weird.  It has the same value -1 in this case because 11
% -2 is 1, but how it is related?
Anyway, we have the mod part of divmod used twice, once for each divmod, with
REG_UNUSED stale note, so
(insn 24 15 27 3 (parallel [
            (set (reg:SI 133 [ _30 ])
                (div:SI (const_int 11 [0xb])
                    (reg/v:SI 130 [ f ])))
            (set (reg:SI 134)
                (mod:SI (const_int 11 [0xb])
                    (reg/v:SI 130 [ f ])))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":9:10 681 {*divmodsi4_const}
     (expr_list:REG_DEAD (reg/v:SI 130 [ f ])
        (expr_list:REG_UNUSED (reg:SI 134)
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))
...
(insn 32 28 33 3 (parallel [
            (set (reg:SI 140 [ _35 ])
                (minus:SI (reg:SI 138)
                    (reg:SI 134)))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":11:15 393 {*subsi_1}
     (expr_list:REG_DEAD (reg:SI 137 [ _78 ])
        (expr_list:REG_DEAD (reg:SI 136 [ _32 ])
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))
...
(insn 57 48 59 5 (parallel [
            (set (reg:SI 149 [ _19 ])
                (div:SI (const_int 11 [0xb])
                    (reg/v:SI 131 [ f ])))
            (set (reg:SI 150)
                (mod:SI (const_int 11 [0xb])
                    (reg/v:SI 131 [ f ])))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":9:10 681 {*divmodsi4_const}
     (expr_list:REG_DEAD (reg/v:SI 131 [ f ])
        (expr_list:REG_UNUSED (reg:SI 150)
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))
...
(insn 65 61 66 5 (parallel [
            (set (reg:SI 156 [ _24 ])
                (minus:SI (reg:SI 154)
                    (reg:SI 150)))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":11:15 393 {*subsi_1}
     (expr_list:REG_DEAD (reg:SI 153 [ _76 ])
        (expr_list:REG_DEAD (reg:SI 152 [ _22 ])
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))
Next comes the loop_invariant pass, which hoists
(insn 12 2 3 2 (set (reg:SI 124 [ a_lsm.12 ])
        (mem/c:SI (symbol_ref:DI ("a") [flags 0x2]  <var_decl 0x7fb89b3bbe40
a>) [1 a+0 S4 A32])) 100 {*movsi_internal}
     (nil))
(insn 3 12 15 2 (set (reg:QI 125 [ a_lsm_flag.13 ])
        (const_int 0 [0])) "pr121675.c":18:1 102 {*movqi_internal}
     (nil))
(insn 15 3 24 2 (set (reg/v:SI 130 [ f ])
        (const_int -2 [0xfffffffffffffffe])) "pr121675.c":6:5 100
{*movsi_internal}
     (nil))
(insn 24 15 29 2 (parallel [
            (set (reg:SI 133 [ _30 ])
                (div:SI (const_int 11 [0xb])
                    (reg/v:SI 130 [ f ])))
            (set (reg:SI 134)
                (mod:SI (const_int 11 [0xb])
                    (reg/v:SI 130 [ f ])))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":9:10 681 {*divmodsi4_const}
     (expr_list:REG_DEAD (reg/v:SI 130 [ f ])
        (expr_list:REG_UNUSED (reg:SI 134)
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))
(insn 29 24 146 2 (set (reg:SI 138)
        (const_int 0 [0])) "pr121675.c":11:11 100 {*movsi_internal}
     (nil))
(insn 146 29 151 2 (set (reg:QI 166)
        (const_int 1 [0x1])) "pr121675.c":12:7 102 {*movqi_internal}
     (nil))
(insn 151 146 80 2 (set (reg:SI 168)
        (const_int 1 [0x1])) "pr121675.c":12:7 100 {*movsi_internal}
     (nil))
before the loop and keeps
(insn 32 13 33 3 (parallel [
            (set (reg:SI 140 [ _35 ])
                (minus:SI (reg:SI 138)
                    (reg:SI 134)))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":11:15 393 {*subsi_1}
     (expr_list:REG_DEAD (reg:SI 137 [ _78 ])
        (expr_list:REG_DEAD (reg:SI 136 [ _32 ])
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))
and
(insn 65 156 66 3 (parallel [
            (set (reg:SI 156 [ _24 ])
                (minus:SI (reg:SI 138)
                    (reg:SI 150)))
            (clobber (reg:CC 17 flags))
        ]) "pr121675.c":11:15 393 {*subsi_1}
     (expr_list:REG_DEAD (reg:SI 153 [ _76 ])
        (expr_list:REG_DEAD (reg:SI 152 [ _22 ])
            (expr_list:REG_UNUSED (reg:CC 17 flags)
                (nil)))))
in the loop.  Except that r150 setter (the other divmod) was removed, so r150
is now uninitialized.
So possibly another use of stale REG_UNUSED in single_set or something like
that?

Reply via email to