gimple-fold.c (get_base_constructor): Add VIEW_CONVERT case, handle all tcc_constant...
authorRichard Biener <rguenther@suse.de>
Tue, 19 Jul 2016 14:16:54 +0000 (14:16 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 19 Jul 2016 14:16:54 +0000 (14:16 +0000)
2016-07-19  Richard Biener  <rguenther@suse.de>

* gimple-fold.c (get_base_constructor): Add VIEW_CONVERT case,
handle all tcc_constant bases and valueize SSA names.
* tree-ssa-sccvn.c (fully_constant_vn_reference_p): Handle
tcc_constant bases.

* c-c++-common/vector-subscript-6.c: New testcase.
* c-c++-common/vector-subscript-7.c: Likewise.

From-SVN: r238475

gcc/ChangeLog
gcc/gimple-fold.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/vector-subscript-6.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/vector-subscript-7.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.c

index b00409c79517b5efd514b56cbda1ff1424377e75..b6d25c3817924e0a69c33d8ddeb4f343d7a3de47 100644 (file)
@@ -1,3 +1,10 @@
+2016-07-19  Richard Biener  <rguenther@suse.de>
+
+       * gimple-fold.c (get_base_constructor): Add VIEW_CONVERT case,
+       handle all tcc_constant bases and valueize SSA names.
+       * tree-ssa-sccvn.c (fully_constant_vn_reference_p): Handle
+       tcc_constant bases.
+
 2016-07-19  David Malcolm  <dmalcolm@redhat.com>
 
        * function-tests.c (selftest::verify_three_block_rtl_cfg): Verify
index cbfcc2f0eae626f7437c97265c70330005da394b..3a5008839a50aaedde07a6eb4459085caf34f59b 100644 (file)
@@ -5508,6 +5508,9 @@ get_base_constructor (tree base, HOST_WIDE_INT *bit_offset,
         return NULL_TREE;
       base = TREE_OPERAND (base, 0);
     }
+  else if (valueize
+          && TREE_CODE (base) == SSA_NAME)
+    base = valueize (base);
 
   /* Get a CONSTRUCTOR.  If BASE is a VAR_DECL, get its
      DECL_INITIAL.  If BASE is a nested reference into another
@@ -5529,6 +5532,10 @@ get_base_constructor (tree base, HOST_WIDE_INT *bit_offset,
        return init;
       }
 
+    case VIEW_CONVERT_EXPR:
+      return get_base_constructor (TREE_OPERAND (base, 0),
+                                  bit_offset, valueize);
+
     case ARRAY_REF:
     case COMPONENT_REF:
       base = get_ref_base_and_extent (base, &bit_offset2, &size, &max_size,
@@ -5538,11 +5545,13 @@ get_base_constructor (tree base, HOST_WIDE_INT *bit_offset,
       *bit_offset +=  bit_offset2;
       return get_base_constructor (base, bit_offset, valueize);
 
-    case STRING_CST:
     case CONSTRUCTOR:
       return base;
 
     default:
+      if (CONSTANT_CLASS_P (base))
+       return base;
+
       return NULL_TREE;
     }
 }
index 536fbee9ec166dcd440101d3371ddecbe18c24b1..930a6e8f825305a22a7df4accc66dc238327c460 100644 (file)
@@ -1,3 +1,8 @@
+2016-07-19  Richard Biener  <rguenther@suse.de>
+
+       * c-c++-common/vector-subscript-6.c: New testcase.
+       * c-c++-common/vector-subscript-7.c: Likewise.
+
 2016-07-19  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>
 
        * gcc.dg/params/blocksort-part.c: Conditionally define Int32 
diff --git a/gcc/testsuite/c-c++-common/vector-subscript-6.c b/gcc/testsuite/c-c++-common/vector-subscript-6.c
new file mode 100644 (file)
index 0000000..b430e9c
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fno-tree-ccp -fdump-tree-fre1" } */
+
+typedef int v4si __attribute__ ((vector_size (16)));
+
+int
+main (int argc, char** argv)
+{
+  int i = 2;
+  int j = ((v4si){0, 1, 2, 3})[i];
+  return ((v4si){1, 2, 42, 0})[j];
+}
+
+/* { dg-final { scan-tree-dump "return 42;" "fre1" } } */
diff --git a/gcc/testsuite/c-c++-common/vector-subscript-7.c b/gcc/testsuite/c-c++-common/vector-subscript-7.c
new file mode 100644 (file)
index 0000000..e8418f2
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-ccp1" } */
+
+typedef int v4si __attribute__ ((vector_size (16)));
+
+int
+main (int argc, char** argv)
+{
+  int i = 2;
+  int j = ((v4si){0, 1, 2, 3})[i];
+  return ((v4si){1, 2, 42, 0})[j];
+}
+
+/* { dg-final { scan-tree-dump "return 42;" "ccp1" } } */
index e6853420b6c90cd57fc7616837ed1c646d24da12..e889d6063e6ec99a1a00ee778ecd0816dcf3e3d7 100644 (file)
@@ -1337,6 +1337,11 @@ fully_constant_vn_reference_p (vn_reference_t ref)
       unsigned i;
       for (i = 0; i < operands.length (); ++i)
        {
+         if (TREE_CODE_CLASS (operands[i].opcode) == tcc_constant)
+           {
+             ++i;
+             break;
+           }
          if (operands[i].off == -1)
            return NULL_TREE;
          off += operands[i].off;