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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This seems to be clearly a shrink-wrapping bug.
Before pro_and_epilogue we have in RTL:
(note 4 1 2 2 [bb 2] NOTE_INSN_BASIC_BLOCK)
(note 2 4 3 2 NOTE_INSN_FUNCTION_BEG)
(insn 3 2 34 2 (set (reg/v:QI 0 ax [orig:84 l ] [84])
        (const_int -1 [0xffffffffffffffff])) "pr103860.c":14:10 83
{*movqi_internal}
     (expr_list:REG_EQUAL (const_int -1 [0xffffffffffffffff])
        (nil)))

(code_label 34 3 6 3 7 (nil) [1 uses])
(note 6 34 7 3 [bb 3] NOTE_INSN_BASIC_BLOCK)
(note 7 6 10 3 NOTE_INSN_DELETED)
(insn 10 7 11 3 (set (reg:CCGOC 17 flags)
        (compare:CCGOC (mem/c:SI (symbol_ref:DI ("d") [flags 0x2]  <var_decl
0x7f8ba5c9ac60 d>) [1 d+0 S4 A32])
            (const_int 0 [0]))) 7 {*cmpsi_ccno_1}
     (nil))
(jump_insn 11 10 13 3 (set (pc)
        (if_then_else (ge (reg:CCGOC 17 flags)
                (const_int 0 [0]))
            (label_ref 16)
            (pc))) 873 {*jcc}
     (int_list:REG_BR_PROB 118111604 (nil))
 -> 16)

(code_label 13 11 12 5 5 (nil) [1 uses])
(note 12 13 52 5 [bb 5] NOTE_INSN_BASIC_BLOCK)
(jump_insn 52 12 53 5 (set (pc)
        (label_ref 13)) 874 {jump}
     (nil)
 -> 13)

(barrier 53 52 16)

(code_label 16 53 17 6 4 (nil) [1 uses])
(note 17 16 19 6 [bb 6] NOTE_INSN_BASIC_BLOCK)
(jump_insn 19 17 20 6 (set (pc)
        (if_then_else (eq (reg:CCGOC 17 flags)
                (const_int 0 [0]))
            (label_ref 27)
            (pc))) "pr103860.c":18:10 873 {*jcc}
     (int_list:REG_BR_PROB 536870916 (nil))

The problem is that shrink-wrapping decides to put the
(insn/f 55 77 56 12 (parallel [
            (set (reg/f:DI 7 sp)
                (plus:DI (reg/f:DI 7 sp)
                    (const_int -8 [0xfffffffffffffff8])))
            (clobber (reg:CC 17 flags))
            (clobber (mem:BLK (scratch) [0  A8]))
        ]) "pr103860.c":12:1 -1
     (expr_list:REG_CFA_ADJUST_CFA (set (reg/f:DI 7 sp)
            (plus:DI (reg/f:DI 7 sp)
                (const_int -8 [0xfffffffffffffff8])))
        (nil)))
instruction on the edge in between bb3 and bb6, but that isn't correct, because
the flags register is live on that edge (set in insn 10, used in insns 11 and
19) and the prologue instruction clobbers it.

So we end up with:
main:
        movl    d(%rip), %edx
        movl    $-1, %eax
        testl   %edx, %edx
        jns     .L12
.L11:
        jmp     .L11
.L12:
        subq    $8, %rsp
.L4:
        je      .L6
        movq    f@GOTPCREL(%rip), %rax
        movl    $0, (%rax)
        movl    $0, 0
        ud2
.L6:
(.palign* and .cfi* directives and useless labels manually elided), which is
wrong, because je .L6 is done depending on whether %rsp was 8 before the
subtration (pretty much never), rather than depending on whether %edx is 0.

Reply via email to