Patchwork Another fix for TARGET_READ_MODIFY_WRITE i386 peepholes (PR target/53358)

login
register
mail settings
Submitter Jakub Jelinek
Date May 15, 2012, 11:47 a.m.
Message ID <20120515114713.GK16117@tyan-ft48-01.lab.bos.redhat.com>
Download mbox | patch
Permalink /patch/159299/
State New
Headers show

Comments

Jakub Jelinek - May 15, 2012, 11:47 a.m.
Hi!

This is a similar problem as PR52086, but back then when looking
at whether other peepholes might need similar treatment I didn't think
about the possibility that addqi_1 pattern would allow non-q constraint
register.  Apparently it does in some of the alternatives, the insn is then
emitted widened as addl etc., but for addqi_2 it isn't possible (it adds to
memory).

Fixed thusly, bootstrapped/regtested on i686-linux, ok for trunk/4.7?

2012-05-15  Jakub Jelinek  <jakub@redhat.com>

	PR target/53358
	* config/i386/i386.md (*addqi_2 peephole with QImode addition): Check
	that operands[2] is either immediate, or q_regs_operand.

	* gcc.dg/pr53358.c: New test.


	Jakub
Uros Bizjak - May 15, 2012, 1:33 p.m.
On Tue, May 15, 2012 at 1:47 PM, Jakub Jelinek <jakub@redhat.com> wrote:

> This is a similar problem as PR52086, but back then when looking
> at whether other peepholes might need similar treatment I didn't think
> about the possibility that addqi_1 pattern would allow non-q constraint
> register.  Apparently it does in some of the alternatives, the insn is then
> emitted widened as addl etc., but for addqi_2 it isn't possible (it adds to
> memory).
>
> Fixed thusly, bootstrapped/regtested on i686-linux, ok for trunk/4.7?
>
> 2012-05-15  Jakub Jelinek  <jakub@redhat.com>
>
>        PR target/53358
>        * config/i386/i386.md (*addqi_2 peephole with QImode addition): Check
>        that operands[2] is either immediate, or q_regs_operand.
>
>        * gcc.dg/pr53358.c: New test.

OK.

Thanks,
Uros.

Patch

--- gcc/config/i386/i386.md.jj	2012-05-02 09:42:33.000000000 +0200
+++ gcc/config/i386/i386.md	2012-05-15 10:48:19.197020618 +0200
@@ -17209,6 +17209,9 @@  (define_peephole2
   "(TARGET_READ_MODIFY_WRITE || optimize_insn_for_size_p ())
    && peep2_reg_dead_p (4, operands[0])
    && !reg_overlap_mentioned_p (operands[0], operands[1])
+   && (<MODE>mode != QImode
+       || immediate_operand (operands[2], QImode)
+       || q_regs_operand (operands[2], QImode))
    && ix86_match_ccmode (peep2_next_insn (3),
 			 (GET_CODE (operands[3]) == PLUS
 			  || GET_CODE (operands[3]) == MINUS)
--- gcc/testsuite/gcc.dg/pr53358.c.jj	2012-05-15 11:54:40.680128157 +0200
+++ gcc/testsuite/gcc.dg/pr53358.c	2012-05-15 11:54:47.698086318 +0200
@@ -0,0 +1,22 @@ 
+/* PR target/53358 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+/* { dg-additional-options "-fpic" { target fpic } } */
+/* { dg-additional-options "-mtune=pentium4" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
+
+struct S { unsigned char s, t[17]; };
+int bar (void);
+
+void
+foo (struct S *x)
+{
+  unsigned char i, z;
+  if (bar ())
+    {
+      z = bar ();
+      bar ();
+      x->s += z;
+      for (i = 0; i < x->s; i++)
+	x->t[i] = bar ();
+    }
+}