aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Pinski <andrew_pinski@playstation.sony.com>2008-03-31 18:22:05 +0000
committerAndrew Pinski <pinskia@gcc.gnu.org>2008-03-31 11:22:05 -0700
commita12bdb97c9bb28dc996017ec826612ac61dbe846 (patch)
tree05015805c094c492567941926cc55180a8afe552
parent2d4bba805eeeea81ee9e566e569528de83876e08 (diff)
downloadgcc-a12bdb97c9bb28dc996017ec826612ac61dbe846.zip
gcc-a12bdb97c9bb28dc996017ec826612ac61dbe846.tar.gz
gcc-a12bdb97c9bb28dc996017ec826612ac61dbe846.tar.bz2
re PR tree-optimization/30186 (accessing an element via a "pointer" on a vector does not cause vec_extract to be used (non-zero index))
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 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. From-SVN: r133766
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/fold-const.c28
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/vector-1.c36
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/vector-2.c46
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/vector-1.c32
6 files changed, 155 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7ff0adc..c3e9ffd 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 6e5d940..9fa3137 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -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)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2dde540..b62c44e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..ff21d68
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/vector-1.c
@@ -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
index 0000000..55330dd
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/vector-2.c
@@ -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
index 0000000..5b07c67
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/vector-1.c
@@ -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" } } */
+
+