[backport from gcc-4.7/trunk r183830, fixes PR52086 regression in code added for PR49095 ] Date: Thu, 2 Feb 2012 09:15:17 +0100 From: Jakub Jelinek Subject: [PATCH] Fix i?86 mem += reg + comparison peephole (PR target/52086) List-Archive: Hi! This peephole, as shown on the testcase, happily transforms a QImode memory load into a register, followed by SImode addition of that reg and %ebp, followed by QImode store of that back into the same memory and QImode comparison of that with zero into a QImode addition of the register to the memory with setting flags instead of clobbering them. The problem with that is that for -m32 %ebp can't be used in QImode instructions. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? Date: Thu, 2 Feb 2012 10:15:31 +0100 From: Jakub Jelinek Subject: Re: [PATCH] Fix i?86 mem += reg + comparison peephole (PR target/52086) List-Archive: On Thu, Feb 02, 2012 at 10:02:09AM +0100, Uros Bizjak wrote: > OK, Thanks. > probably we also need to backport this fix to other release branches. No, while I didn't remember it, svn blame revealed that these peepholes were my fault, added for PR49095 just for 4.7+. Jakub gcc/ 2012-02-02 Jakub Jelinek PR target/52086 * config/i386/i386.md (*addqi_2 peephole with SImode addition): Check that operands[2] is either immediate, or q_regs_operand. gcc/testsuite/ 2012-02-02 Jakub Jelinek PR target/52086 * gcc.dg/pr52086.c: New test. --- gcc-4.6.2/gcc/config/i386/i386.md.~1~ 2012-02-05 18:09:30.000000000 +0100 +++ gcc-4.6.2/gcc/config/i386/i386.md 2012-02-05 18:11:11.000000000 +0100 @@ -17239,6 +17239,9 @@ (define_peephole2 && REG_P (operands[0]) && REG_P (operands[4]) && REGNO (operands[0]) == REGNO (operands[4]) && peep2_reg_dead_p (4, operands[0]) + && (mode != QImode + || immediate_operand (operands[2], SImode) + || q_regs_operand (operands[2], SImode)) && !reg_overlap_mentioned_p (operands[0], operands[1]) && ix86_match_ccmode (peep2_next_insn (3), (GET_CODE (operands[3]) == PLUS --- gcc-4.6.2/gcc/testsuite/gcc.dg/pr52086.c.~1~ 1970-01-01 01:00:00.000000000 +0100 +++ gcc-4.6.2/gcc/testsuite/gcc.dg/pr52086.c 2012-02-05 18:11:11.000000000 +0100 @@ -0,0 +1,21 @@ +/* PR target/52086 */ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-options "-O2 -fpic" { target fpic} } */ + +struct S { char a; char b[100]; }; +int bar (void); +int baz (int); + +void +foo (struct S *x) +{ + if (bar () & 1) + { + char c = bar (); + baz (4); + x->a += c; + while (x->a) + x->b[c] = bar (); + } +}