This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR29474: Don't canonicalize commutative operands during reload


Hi,

Below is patch for a problem which is rather difficult to reproduce. A 
number of conditions have to be met, so currently I can only reproduce it 
with 4.1, but I believe the problem still exists in the current gcc.

This example demonstrates the problem of what happens during reload:

+Reloads for insn # 200
+Reload 0: reload_in (SI) = (post_inc:SI (reg/v/f:SI 39 [ inSI.1307 ]))
+       reload_out (SI) = (post_inc:SI (reg/v/f:SI 39 [ inSI.1307 ]))
+       ADDR_REGS, RELOAD_FOR_OPERAND_ADDRESS (opnum = 2), inc by 2
+       reload_in_reg: (post_inc:SI (reg/v/f:SI 39 [ inSI.1307 ]))
+       reload_reg_rtx: (reg:SI 11 %a3)
+Reload 1: reload_in (HI) = (mem:HI (post_inc:SI (reg/v/f:SI 39 [ inSI.1307 ])) [116 S2 A16])
+       DATA_REGS, RELOAD_FOR_INPUT (opnum = 2), optional
+       reload_in_reg: (mem:HI (post_inc:SI (reg/v/f:SI 39 [ inSI.1307 ])) [116 S2 A16])


-(insn 200 199 201 24 /tmp/vtk-vtkImageMaskBits.ii:33307 (set (reg:HI 80)
-        (and:HI (mem:HI (post_inc:SI (reg/v/f:SI 39 [ inSI.1307 ])) [116 S2 A16])
-            (subreg:HI (reg:SI 79) 2))) 172 {andhi3} (insn_list:REG_DEP_TRUE 199 (nil))
-    (expr_list:REG_INC (reg/v/f:SI 39 [ inSI.1307 ])
-        (expr_list:REG_DEAD (reg:SI 79)
-            (nil))))
+(insn 200 442 201 24 /tmp/vtk-vtkImageMaskBits.ii:33307 (set (reg:HI 0 %d0 [80])
+        (and:HI (mem:HI (reg:SI 11 %a3) [116 S2 A16])
+            (reg:HI 0 %d0 [orig:79+2 ] [79]))) 172 {andhi3} (insn_list:REG_DEP_TRUE 199 (nil))
+    (nil))

The conditions for the problem to trigger are:
1) we need an instruction with commutative operands.
2) one operand has to include a auto-inc operand.
3) reload has to exchange the operands to satisfy instruction constraints.
4) a register in the instruction has to be reloaded.

If all conditions are met, reload1.c:reload_as_needed() will call 
validate_replace_rtx(), which then attempts to change the operands back 
and since constraints aren't checked at this time it will succeed. A bit 
later when constraints are checked, it will fail this instruction.

The simplest solution I've found is to simple disable this operand swap 
while reload is active.
Patch is tested on m68k-linux/i686-linux.

bye, Roman

200x-xx-xx  Roman Zippel <zippel@linux-m68k.org>

	PR middle-end/29474
	* gcc/recog.c (validate_replace_rtx_1): Prevent swap of 
	commutative operands during reload

---

 gcc/recog.c |    1 +
 1 file changed, 1 insertion(+)

Index: gcc/gcc/recog.c
===================================================================
--- gcc.orig/gcc/recog.c	2007-04-22 05:03:09.000000000 +0200
+++ gcc/gcc/recog.c	2007-04-22 05:04:22.000000000 +0200
@@ -554,6 +554,7 @@ validate_replace_rtx_1 (rtx *loc, rtx fr
      simplifications, as it is not our job.  */
 
   if (SWAPPABLE_OPERANDS_P (x)
+      && !reload_in_progress
       && swap_commutative_operands_p (XEXP (x, 0), XEXP (x, 1)))
     {
       validate_change (object, loc,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]