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.
Created attachment 33050 [details] gcc49-pr61673.patch Untested fix.
Author: jakub Date: Tue Jul 8 15:39:36 2014 New Revision: 212364 URL: https://gcc.gnu.org/viewcvs?rev=212364&root=gcc&view=rev Log: PR rtl-optimization/61673 * combine.c (simplify_comparison): Test just mode's sign bit in tmode rather than the sign bit and any bits above it. * gcc.c-torture/execute/pr61673.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr61673.c Modified: trunk/gcc/ChangeLog trunk/gcc/combine.c trunk/gcc/testsuite/ChangeLog
Author: jakub Date: Tue Jul 8 15:43:39 2014 New Revision: 212365 URL: https://gcc.gnu.org/viewcvs?rev=212365&root=gcc&view=rev Log: PR rtl-optimization/61673 * combine.c (simplify_comparison): Test just mode's sign bit in tmode rather than the sign bit and any bits above it. * gcc.c-torture/execute/pr61673.c: New test. Added: branches/gcc-4_9-branch/gcc/testsuite/gcc.c-torture/execute/pr61673.c Modified: branches/gcc-4_9-branch/gcc/ChangeLog branches/gcc-4_9-branch/gcc/combine.c branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
Fixed.