From: Andrew Pinski Date: Mon, 31 Mar 2008 18:22:05 +0000 (+0000) Subject: re PR tree-optimization/30186 (accessing an element via a "pointer" on a vector does... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a12bdb97c9bb28dc996017ec826612ac61dbe846;p=gcc.git 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 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 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 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7ff0adc85aa..c3e9ffd27b4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-03-31 Andrew Pinski + + 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 * tlink.c (scan_linker_output): Look for symbol name in single diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 6e5d9403e70..9fa31376864 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 */ + 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 2dde540514c..b62c44e6650 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2008-03-31 Andrew Pinski + + 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 * 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 00000000000..ff21d68ca7b --- /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 00000000000..55330dd6606 --- /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 00000000000..5b07c67a2c6 --- /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" } } */ + +