https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61673
Bug ID: 61673 Summary: [4.9/4.10 Regression] Miscompilation of _gnutls_hostname_compare on s390 Product: gcc Version: 4.9.1 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: rtl-optimization Assignee: jakub at gcc dot gnu.org Reporter: jakub at gcc dot gnu.org Target: s390-linux char e; __attribute__((noinline, noclone)) void foo (const char *x) { char d = x[0]; int c = d; if ((c >= 0 && c <= 0x7f) == 0) e = d; } int main () { const char c[] = { 0x54, 0x87 }; e = 0x21; foo (c); if (e != 0x21) __builtin_abort (); foo (c + 1); if (e != 0x87) __builtin_abort (); return 0; } is miscompiled supposedly starting with r202393. Before combine we have: (insn 7 6 8 2 (parallel [ (set (reg:SI 47 [ D.1404 ]) (and:SI (subreg:SI (reg/v:QI 44 [ d ]) 0) (const_int 255 [0xff]))) (clobber (reg:CC 33 %cc)) ]) gnutls2.c:8 455 {*andsi3_esa} (expr_list:REG_UNUSED (reg:CC 33 %cc) (nil))) (insn 8 7 9 2 (set (reg:CCU 33 %cc) (compare:CCU (reg:SI 47 [ D.1404 ]) (const_int 127 [0x7f]))) gnutls2.c:8 39 {*cmpsi_ccu} (expr_list:REG_DEAD (reg:SI 47 [ D.1404 ]) (nil))) (jump_insn 9 8 10 2 (set (pc) (if_then_else (leu (reg:CCU 33 %cc) (const_int 0 [0])) (label_ref:SI 15) (pc))) gnutls2.c:8 599 {*cjump_31} (expr_list:REG_DEAD (reg:CCU 33 %cc) (int_list:REG_BR_PROB 3900 (nil))) -> 15) and combine turns this into: (note 7 6 8 2 NOTE_INSN_DELETED) (insn 8 7 9 2 (parallel [ (set (reg:CCZ 33 %cc) (compare:CCZ (and:SI (subreg:SI (reg/v:QI 44 [ d ]) 0) (const_int -128 [0xffffffffffffff80])) (const_int 0 [0]))) (clobber (scratch:SI)) ]) gnutls2.c:8 453 {*andsi3_cconly} (nil)) (jump_insn 9 8 10 2 (set (pc) (if_then_else (eq (reg:CCZ 33 %cc) (const_int 0 [0])) (label_ref:SI 15) (pc))) gnutls2.c:8 599 {*cjump_31} (expr_list:REG_DEAD (reg:CCU 33 %cc) (int_list:REG_BR_PROB 3900 (nil))) -> 15) The -128 should have been 128, we want to test the sign bit of QImode rather than also any of the higher bits that contain garbage.