OSDN Git Service

2008-03-31 Andrew Pinski <andrew_pinski@playstation.sony.com>
authorpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 31 Mar 2008 18:22:05 +0000 (18:22 +0000)
committerpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 31 Mar 2008 18:22:05 +0000 (18:22 +0000)
        PR middle-end/30186
        * fold-const.c (fold_indirect_ref_1): Support accessing non first
        element of the vector via a pointer.

2008-03-31  Andrew Pinski  <andrew_pinski@playstation.sony.com>

        PR middle-end/30186
        * gcc.dg/tree-ssa/vector-1.c: New testcase.
        * gcc.c-torture/execute/vector-1.c: New testcase.
        * gcc.c-torture/execute/vector-2.c: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@133766 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/vector-1.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/execute/vector-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/vector-1.c [new file with mode: 0644]

index 7ff0adc..c3e9ffd 100644 (file)
@@ -1,3 +1,9 @@
+2008-03-31  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       PR middle-end/30186
+       * fold-const.c (fold_indirect_ref_1): Support accessing non first
+       element of the vector via a pointer.
+
 2008-03-31  Ian Lance Taylor  <iant@google.com>
 
        * tlink.c (scan_linker_output): Look for symbol name in single
index 6e5d940..9fa3137 100644 (file)
@@ -14963,6 +14963,34 @@ fold_indirect_ref_1 (tree type, tree op0)
        }
     }
 
+  /* ((foo*)&vectorfoo)[1] => BIT_FIELD_REF<vectorfoo,...> */
+  if (TREE_CODE (sub) == POINTER_PLUS_EXPR
+      && TREE_CODE (TREE_OPERAND (sub, 1)) == INTEGER_CST)
+    { 
+      tree op00 = TREE_OPERAND (sub, 0);
+      tree op01 = TREE_OPERAND (sub, 1);
+      tree op00type;
+      
+      STRIP_NOPS (op00);
+      op00type = TREE_TYPE (op00);
+      if (TREE_CODE (op00) == ADDR_EXPR
+          && TREE_CODE (TREE_TYPE (op00type)) == VECTOR_TYPE
+          && type == TREE_TYPE (TREE_TYPE (op00type)))
+       { 
+         HOST_WIDE_INT offset = tree_low_cst (op01, 0);
+         tree part_width = TYPE_SIZE (type);
+         unsigned HOST_WIDE_INT part_widthi = tree_low_cst (part_width, 0)/BITS_PER_UNIT;
+         unsigned HOST_WIDE_INT indexi = offset * BITS_PER_UNIT;
+         tree index = bitsize_int (indexi);
+
+         if (offset/part_widthi <= TYPE_VECTOR_SUBPARTS (TREE_TYPE (op00type)))
+           return fold_build3 (BIT_FIELD_REF, type, TREE_OPERAND (op00, 0),
+                               part_width, index);
+        
+       }
+    }
+
+
   /* ((foo*)&complexfoo)[1] => __imag__ complexfoo */
   if (TREE_CODE (sub) == POINTER_PLUS_EXPR
       && TREE_CODE (TREE_OPERAND (sub, 1)) == INTEGER_CST)
index 2dde540..b62c44e 100644 (file)
@@ -1,3 +1,10 @@
+2008-03-31  Andrew Pinski  <andrew_pinski@playstation.sony.com>
+
+       PR middle-end/30186
+       * gcc.dg/tree-ssa/vector-1.c: New testcase.
+       * gcc.c-torture/execute/vector-1.c: New testcase.
+       * gcc.c-torture/execute/vector-2.c: New testcase.
+
 2008-03-31  Olivier Hainque  <hainque@adacore.com>
 
        * gnat.dg/assign_from_packed_pixels.ads: Support for ...
diff --git a/gcc/testsuite/gcc.c-torture/execute/vector-1.c b/gcc/testsuite/gcc.c-torture/execute/vector-1.c
new file mode 100644 (file)
index 0000000..ff21d68
--- /dev/null
@@ -0,0 +1,36 @@
+/* Check that vector extraction works correctly. */
+
+#define vector __attribute__((vector_size(16) ))
+
+int f0(vector int t)
+{
+  return ((int*)&t)[0];
+}
+int f1(vector int t)
+{
+  return ((int*)&t)[1];
+}
+int f2(vector int t)
+{
+  return ((int*)&t)[2];
+}
+int f3(vector int t)
+{
+  return ((int*)&t)[3];
+}
+int main(void)
+{
+  vector int a = {0, 1, 2, 3};
+  /* Make sure that we have the correct size for the vectors. */
+  if (sizeof(int) != 4)
+    __builtin_exit (0);
+  if (f0(a) != 0)
+    __builtin_abort ();
+  if (f1(a) != 1)
+    __builtin_abort ();
+  if (f2(a) != 2)
+    __builtin_abort ();
+  if (f3(a) != 3)
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/vector-2.c b/gcc/testsuite/gcc.c-torture/execute/vector-2.c
new file mode 100644 (file)
index 0000000..55330dd
--- /dev/null
@@ -0,0 +1,46 @@
+/* Check that vector insertion works correctly. */
+
+#define vector __attribute__((vector_size(16) ))
+
+vector int f0(vector int t, int a)
+{
+ ((int*)&t)[0] = a;
+ return t;
+}
+vector int f1(vector int t, int a)
+{
+ ((int*)&t)[1] = a;
+ return t;
+}
+vector int f2(vector int t, int a)
+{
+ ((int*)&t)[2] = a;
+ return t;
+}
+vector int f3(vector int t, int a)
+{
+ ((int*)&t)[3] = a;
+ return t;
+}
+int main(void)
+{
+  vector int a = {0, 0, 0, 0};
+  vector int b = {1, 0, 0, 0};
+  vector int c = {0, 1, 0, 0};
+  vector int d = {0, 0, 1, 0};
+  vector int e = {0, 0, 0, 1};
+  vector int a0;
+  a0 = f0(a, 1);
+  if (memcmp (&a0, &b, sizeof(a0)))
+    __builtin_abort ();
+  a0 = f1(a, 1);
+  if (memcmp (&a0, &c, sizeof(a0)))
+    __builtin_abort ();
+  a0 = f2(a, 1);
+  if (memcmp (&a0, &d, sizeof(a0)))
+    __builtin_abort ();
+  a0 = f3(a, 1);
+  if (memcmp (&a0, &e, sizeof(a0)))
+    __builtin_abort ();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/vector-1.c b/gcc/testsuite/gcc.dg/tree-ssa/vector-1.c
new file mode 100644 (file)
index 0000000..5b07c67
--- /dev/null
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+/* { dg-options "-w -O1 -fdump-tree-gimple" } */
+
+
+/* We should be able to produce a BIT_FIELD_REF for each of these vector access. */
+#define vector __attribute__((vector_size(16)))
+float f0(vector float t)
+{
+  return ((float*)&t)[0];
+}
+
+float f1(vector float t)
+{
+  return ((float*)&t)[1];
+}
+
+float f2(vector float t)
+{
+  return ((float*)&t)[2];
+}
+
+float f3(vector float t)
+{
+  return ((float*)&t)[3];
+}
+
+
+/* { dg-final { scan-tree-dump-times "BIT_FIELD_REF" 4 "gimple"} } */
+
+/* { dg-final { cleanup-tree-dump "gimple" } } */
+
+