http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60116
--- Comment #11 from Uroš Bizjak <ubizjak at gmail dot com> ---
OK, confirmed using "-Os -m32" with
gcc version 4.9.0 20140207 (experimental) [trunk revision 207597] (GCC)
on CentOS 5.10.
It looks like a fault in the combine pass.
Before combine, we have:
...
(insn 14 11 15 2 (set (reg:SI 101 [ D.1782 ])
(mem/c:SI (symbol_ref:SI ("d") [flags 0x2] <var_decl 0x2b47ff9e1ed8d>)
[2 d+0 S4 A32])) t.c:18 90 {*movsi_internal}
(nil))
...
(insn 33 32 34 5 (set (reg:SI 113 [ D.1782 ])
(sign_extend:SI (reg:QI 91 [ D.1785 ]))) t.c:17 148 {extendqisi2}
(nil))
(insn 34 33 35 5 (set (reg:SI 114 [ D.1782 ])
(not:SI (reg:SI 113 [ D.1782 ]))) t.c:17 510 {*one_cmplsi2_1}
(expr_list:REG_DEAD (reg:SI 113 [ D.1782 ])
(nil)))
(insn 35 34 37 5 (parallel [
(set (reg:DI 115 [ D.1786 ])
(sign_extend:DI (reg:SI 114 [ D.1782 ])))
(clobber (reg:CC 17 flags))
(clobber (scratch:SI))
]) t.c:17 143 {extendsidi2_1}
(expr_list:REG_DEAD (reg:SI 114 [ D.1782 ])
(expr_list:REG_UNUSED (reg:CC 17 flags)
(nil))))
(insn 37 35 38 5 (parallel [
(set (reg:SI 117)
(ior:SI (subreg:SI (reg:DI 115 [ D.1786 ]) 0)
(subreg:SI (reg:DI 115 [ D.1786 ]) 4)))
(clobber (reg:CC 17 flags))
]) t.c:17 420 {*iorsi_1}
(expr_list:REG_DEAD (reg:DI 115 [ D.1786 ])
(expr_list:REG_UNUSED (reg:CC 17 flags)
(nil))))
(insn 38 37 39 5 (set (reg:CCZ 17 flags)
(compare:CCZ (reg:SI 117)
(const_int 0 [0]))) t.c:17 3 {*cmpsi_ccno_1}
(expr_list:REG_DEAD (reg:SI 117)
(nil)))
(insn 39 38 41 5 (set (reg:QI 119)
(ne:QI (reg:CCZ 17 flags)
(const_int 0 [0]))) t.c:17 624 {*setcc_qi}
(expr_list:REG_DEAD (reg:CCZ 17 flags)
(nil)))
(insn 41 39 83 5 (set (reg:CCZ 17 flags)
(compare:CCZ (reg:SI 101 [ D.1782 ])
(const_int 0 [0]))) t.c:18 3 {*cmpsi_ccno_1}
(nil))
(insn 83 41 42 5 (set (reg:SI 122 [ D.1787 ])
(zero_extend:SI (reg:QI 119))) 138 {*zero_extendqisi2}
(expr_list:REG_DEAD (reg:QI 119)
(nil)))
(jump_insn 42 83 43 5 (set (pc)
(if_then_else (eq (reg:CCZ 17 flags)
(const_int 0 [0]))
(label_ref 47)
(pc))) t.c:18 628 {*jcc_1}
(expr_list:REG_DEAD (reg:CCZ 17 flags)
(int_list:REG_BR_PROB 5000 (nil)))
-> 47)
Please note (insn 41) that sets flags for (jump_insn 42), comparing (reg:SI
101) a.k.a "d" with zero.
Later, combine mass-deletes everything from (insn 33) to (insn 83) to
substitute (insn 83) with constant load:
...
(insn 14 11 15 2 (set (reg:SI 101 [ D.1782 ])
(mem/c:SI (symbol_ref:SI ("d") [flags 0x2] <var_decl 0x2b47ff9e1ed8d>)
[2 d+0 S4 A32])) t.c:18 90 {*movsi_internal}
(nil))
...
(note 33 32 34 5 NOTE_INSN_DELETED)
(note 34 33 35 5 NOTE_INSN_DELETED)
(note 35 34 37 5 NOTE_INSN_DELETED)
(note 37 35 39 5 NOTE_INSN_DELETED)
(note 39 37 41 5 NOTE_INSN_DELETED)
(note 41 39 83 5 NOTE_INSN_DELETED)
(insn 83 41 42 5 (set (reg:SI 122 [ D.1787 ])
(const_int 1 [0x1])) 90 {*movsi_internal}
(nil))
(jump_insn 42 83 43 5 (set (pc)
(if_then_else (eq (reg:CCZ 17 flags)
(const_int 0 [0]))
(label_ref 47)
(pc))) t.c:18 628 {*jcc_1}
(expr_list:REG_DEAD (reg:CCZ 17 flags)
(int_list:REG_BR_PROB 5000 (nil)))
-> 47)
Unfortunately unrelated (insn 41) is also killed, so flags are taken from
unrelated operation (that happens to be insn 32, just above insn 33).
Things go downhill from there.