]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/116057 - wrong code with CCP and vector CTORs
authorRichard Biener <rguenther@suse.de>
Wed, 24 Jul 2024 11:16:35 +0000 (13:16 +0200)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 24 Jul 2024 12:08:44 +0000 (14:08 +0200)
The following fixes an issue with CCPs likely_value when faced with
a vector CTOR containing undef SSA names and constants.  This should
be classified as CONSTANT and not UNDEFINED.

PR tree-optimization/116057
* tree-ssa-ccp.cc (likely_value): Also walk CTORs in stmt
operands to look for constants.

* gcc.dg/torture/pr116057.c: New testcase.

gcc/testsuite/gcc.dg/torture/pr116057.c [new file with mode: 0644]
gcc/tree-ssa-ccp.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr116057.c b/gcc/testsuite/gcc.dg/torture/pr116057.c
new file mode 100644 (file)
index 0000000..a7021c8
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-additional-options "-Wno-psabi" } */
+
+#define vect8 __attribute__((vector_size(8)))
+
+vect8 int __attribute__((noipa))
+f(int a)
+{
+  int b;
+  vect8 int t={1,1};
+  if(a) return t;
+  return (vect8 int){0, b};
+}
+
+int main ()
+{
+  if (f(0)[0] != 0)
+    __builtin_abort ();
+  return 0;
+}
index de83d26d311a8329b7391275fe332898e6f9bc7b..44711018e0ef6b95c8787cb28a23e31a7af094c7 100644 (file)
@@ -762,6 +762,17 @@ likely_value (gimple *stmt)
        continue;
       if (is_gimple_min_invariant (op))
        has_constant_operand = true;
+      else if (TREE_CODE (op) == CONSTRUCTOR)
+       {
+         unsigned j;
+         tree val;
+         FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (op), j, val)
+           if (CONSTANT_CLASS_P (val))
+             {
+               has_constant_operand = true;
+               break;
+             }
+       }
     }
 
   if (has_constant_operand)