Patchwork [i386] : Fix PR 52883, ICE in simplify_const_unary_operation, at simplify-rtx.c:1464

login
register
mail settings
Submitter Uros Bizjak
Date April 9, 2012, 10:01 a.m.
Message ID <CAFULd4YojnEs0zjC1D7s5CR7+hUkJUeEgcRv4qpz=FE1M4_3Ug@mail.gmail.com>
Download mbox | patch
Permalink /patch/151429/
State New
Headers show

Comments

Uros Bizjak - April 9, 2012, 10:01 a.m.
Hello!

As pointed out by Eric, there is this little detail in the
documentation w.r.t sign and zero-extending conversions:

"For all conversion operations, X must not be `VOIDmode' because the
mode in which to do the conversion would not be known.  The conversion
must either be done at compile-time or X must be placed into a register.

Taking this into account, the fix is straightforward. We have to
prevent VOIDmode immediates from entering ZERO_EXTEND RTX.

2012-04-09  Uros Bizjak  <ubizjak@gmail.com>

	PR target/52883
	* config/i386/predicates.md (x86_64_zext_general_operand): Prevent
	VOIDmode immediate operands.
	* config/i386/constraints.md (Wz): New constraint.
	* config/i386/i386.md (*zero_extendsidi2_rex64): Use Wz instead of Z.

testsuite/ChangeLog:

2012-04-09  Uros Bizjak  <ubizjak@gmail.com>

	PR target/52883
	* gcc.target/i386/pr52883.c: New testcase.

Patch was tested on x86_64-pc-linux-gnu {,-m32} and committed to mainline SVN.

Uros.

Patch

Index: config/i386/i386.md
===================================================================
--- config/i386/i386.md	(revision 186236)
+++ config/i386/i386.md	(working copy)
@@ -3393,10 +3393,10 @@ 
 
 (define_insn "*zero_extendsidi2_rex64"
   [(set (match_operand:DI 0 "nonimmediate_operand"
-			"=r ,o,?*Ym,?*y,?*Yi,!*x")
+			"=r  ,o,?*Ym,?*y,?*Yi,!*x")
 	(zero_extend:DI
 	 (match_operand:SI 1 "x86_64_zext_general_operand"
-	        	"rmZ,0,r   ,m  ,r   ,m*x")))]
+	        	"rmWz,0,r   ,m  ,r   ,m*x")))]
   "TARGET_64BIT"
   "@
    mov{l}\t{%1, %k0|%k0, %1}
Index: config/i386/constraints.md
===================================================================
--- config/i386/constraints.md	(revision 186236)
+++ config/i386/constraints.md	(working copy)
@@ -18,7 +18,7 @@ 
 ;; <http://www.gnu.org/licenses/>.
 
 ;;; Unused letters:
-;;;     B     H           T  W
+;;;     B     H           T
 ;;;           h  k          v
 
 ;; Integer register constraints.
@@ -199,6 +199,16 @@ 
    instructions)."
   (match_operand 0 "x86_64_immediate_operand"))
 
+;; We use W prefix to denote any number of
+;; constant-or-symbol-reference constraints
+
+(define_constraint "Wz"
+  "32-bit unsigned integer constant, or a symbolic reference known
+   to fit that range (for zero-extending conversion operations that
+   require non-VOIDmode immediate operands)."
+  (and (match_operand 0 "x86_64_zext_immediate_operand")
+       (match_test "GET_MODE (op) != VOIDmode")))
+
 (define_constraint "Z"
   "32-bit unsigned integer constant, or a symbolic reference known
    to fit that range (for immediate operands in zero-extending x86-64
Index: config/i386/predicates.md
===================================================================
--- config/i386/predicates.md	(revision 186236)
+++ config/i386/predicates.md	(working copy)
@@ -341,11 +341,13 @@ 
     (match_operand 0 "general_operand")))
 
 ;; Return true if OP is general operand representable on x86_64
-;; as zero extended constant.
+;; as zero extended constant.  This predicate is used in zero-extending
+;; conversion operations that require non-VOIDmode immediate operands.
 (define_predicate "x86_64_zext_general_operand"
   (if_then_else (match_test "TARGET_64BIT")
     (ior (match_operand 0 "nonimmediate_operand")
-	 (match_operand 0 "x86_64_zext_immediate_operand"))
+	 (and (match_operand 0 "x86_64_zext_immediate_operand")
+	      (match_test "GET_MODE (op) != VOIDmode")))
     (match_operand 0 "general_operand")))
 
 ;; Return true if OP is general operand representable on x86_64
Index: testsuite/gcc.target/i386/pr52883.c
===================================================================
--- testsuite/gcc.target/i386/pr52883.c	(revision 0)
+++ testsuite/gcc.target/i386/pr52883.c	(revision 0)
@@ -0,0 +1,25 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+int a, b, d, e, f, i, j, k, l, m;
+unsigned c;
+int g[] = { }, h[0];
+
+int
+fn1 () {
+  return 0;
+}
+
+void
+fn2 () {
+  c = 0;
+  e = 0;
+  for (;; e = 0)
+    if (f > j) {
+      k = fn1 ();
+      l = (d || k) * b;
+      m = l * a;
+      h[0] = m <= i;
+    } else
+      i = g[c];
+}