This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix TARGET_READ_MODIFY_WRITE peephole2s (PR target/57568)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Uros Bizjak <ubizjak at gmail dot com>, Richard Henderson <rth at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sun, 9 Jun 2013 10:57:24 +0200
- Subject: [PATCH] Fix TARGET_READ_MODIFY_WRITE peephole2s (PR target/57568)
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
These two peephole2s misbehave if it sees e.g.
regN = mem
regN = regN + regN
mem = regN
CC = regN != 0
because transforming it into
mem = mem + regN ; CC = mem != 0
is wrong, I forgot to verify the second operand of the
plusminuslogic_operator doesn't overlap the first operand.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk/4.8 and perhaps also 4.7 (where it is just latent)?
2013-06-09 Jakub Jelinek <jakub@redhat.com>
PR target/57568
* config/i386/i386.md (TARGET_READ_MODIFY_WRITE peepholes): Ensure
that operands[2] doesn't overlap with operands[0].
* gcc.c-torture/execute/pr57568.c: New test.
--- gcc/config/i386/i386.md.jj 2013-06-03 19:15:34.000000000 +0200
+++ gcc/config/i386/i386.md 2013-06-08 21:59:43.416954936 +0200
@@ -16591,6 +16591,7 @@ (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])
+ && !reg_overlap_mentioned_p (operands[0], operands[2])
&& (<MODE>mode != QImode
|| immediate_operand (operands[2], QImode)
|| q_regs_operand (operands[2], QImode))
@@ -16655,6 +16656,7 @@ (define_peephole2
|| immediate_operand (operands[2], SImode)
|| q_regs_operand (operands[2], SImode))
&& !reg_overlap_mentioned_p (operands[0], operands[1])
+ && !reg_overlap_mentioned_p (operands[0], operands[2])
&& ix86_match_ccmode (peep2_next_insn (3),
(GET_CODE (operands[3]) == PLUS
|| GET_CODE (operands[3]) == MINUS)
--- gcc/testsuite/gcc.c-torture/execute/pr57568.c.jj 2013-06-08 22:03:38.861005658 +0200
+++ gcc/testsuite/gcc.c-torture/execute/pr57568.c 2013-06-08 22:03:19.000000000 +0200
@@ -0,0 +1,12 @@
+/* PR target/57568 */
+
+extern void abort (void);
+int a[6][9] = { }, b = 1, *c = &a[3][5];
+
+int
+main ()
+{
+ if (b && (*c = *c + *c))
+ abort ();
+ return 0;
+}
Jakub