[PATCH] Fix tree-vect-generic.c BIT_FIELD_REF creation (PR middle-end/52750)

Jakub Jelinek jakub@redhat.com
Wed Mar 28 13:54:00 GMT 2012


Hi!

The attached testcase shows that already for 32x signed char
vector shuffles using the index element type for computing
BIT_FIELD_REF positions is wrong - bytes 16 and above
in the vector are bits 128 and above, and if idx
has signed char type, that overflows.

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

2012-03-28  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/52750
	* tree-vect-generic.c (vector_element): Perform multiplication
	for pos in bitsizetype type instead of idx type.

	* gcc.c-torture/compile/pr52750.c: New test.

--- gcc/tree-vect-generic.c.jj	2012-03-20 08:51:32.000000000 +0100
+++ gcc/tree-vect-generic.c	2012-03-28 11:20:16.715685934 +0200
@@ -567,8 +567,9 @@ vector_element (gimple_stmt_iterator *gs
       else
         {
 	  tree size = TYPE_SIZE (vect_elt_type);
-          tree pos = fold_build2 (MULT_EXPR, TREE_TYPE (idx), idx, size);
-          return fold_build3 (BIT_FIELD_REF, vect_elt_type, vect, size, pos);
+	  tree pos = fold_build2 (MULT_EXPR, bitsizetype,
+				  fold_convert (bitsizetype, idx), size);
+	  return fold_build3 (BIT_FIELD_REF, vect_elt_type, vect, size, pos);
         }
     }
 
--- gcc/testsuite/gcc.c-torture/compile/pr52750.c.jj	2012-03-28 11:51:12.110286829 +0200
+++ gcc/testsuite/gcc.c-torture/compile/pr52750.c	2012-03-28 11:49:44.000000000 +0200
@@ -0,0 +1,11 @@
+/* PR middle-end/52750 */
+
+typedef signed char V __attribute__((vector_size (32)));
+
+void
+foo (V *x)
+{
+  V m = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
+	  16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
+  *x = __builtin_shuffle (*x, m);
+}

	Jakub



More information about the Gcc-patches mailing list