On November 9, 2019 1:07:18 AM GMT+01:00, Jakub Jelinek <ja...@redhat.com> 
wrote:
>Hi!
>
>On the following testcase we ICE, because gimple_resimplify3 is called
>on a CONSTRUCTOR with 3 elements, which is fine, but it calls
>fold_ternary
>which works only on expression codes with TREE_CODE_LENGTH of 3.
>
>Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok
>for
>trunk?

Ok. 

Thanks, 
Richard. 


>2019-11-09  Jakub Jelinek  <ja...@redhat.com>
>
>       PR tree-optimization/92401
>       * gimple-match-head.c (gimple_resimplify1): Call const_unop only
>       if res_op->code is an expression with code length 1.
>       * gimple-match-head.c (gimple_resimplify2): Call const_binop only
>       if res_op->code is an expression with code length 2.
>       * gimple-match-head.c (gimple_resimplify3): Call fold_ternary only
>       if res_op->code is an expression with code length 3.
>
>       * g++.dg/opt/pr92401.C: New test.
>
>--- gcc/gimple-match-head.c.jj 2019-11-07 17:56:21.983858406 +0100
>+++ gcc/gimple-match-head.c    2019-11-08 09:18:26.650193537 +0100
>@@ -191,7 +191,12 @@ gimple_resimplify1 (gimple_seq *seq, gim
>     {
>       tree tem = NULL_TREE;
>       if (res_op->code.is_tree_code ())
>-      tem = const_unop (res_op->code, res_op->type, res_op->ops[0]);
>+      {
>+        tree_code code = res_op->code;
>+        if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
>+            && TREE_CODE_LENGTH (code) == 1)
>+          tem = const_unop (res_op->code, res_op->type, res_op->ops[0]);
>+      }
>       else
>       tem = fold_const_call (combined_fn (res_op->code), res_op->type,
>                              res_op->ops[0]);
>@@ -252,8 +257,13 @@ gimple_resimplify2 (gimple_seq *seq, gim
>     {
>       tree tem = NULL_TREE;
>       if (res_op->code.is_tree_code ())
>-      tem = const_binop (res_op->code, res_op->type,
>-                         res_op->ops[0], res_op->ops[1]);
>+      {
>+        tree_code code = res_op->code;
>+        if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
>+            && TREE_CODE_LENGTH (code) == 2)
>+          tem = const_binop (res_op->code, res_op->type,
>+                             res_op->ops[0], res_op->ops[1]);
>+      }
>       else
>       tem = fold_const_call (combined_fn (res_op->code), res_op->type,
>                              res_op->ops[0], res_op->ops[1]);
>@@ -325,9 +335,14 @@ gimple_resimplify3 (gimple_seq *seq, gim
>     {
>       tree tem = NULL_TREE;
>       if (res_op->code.is_tree_code ())
>-      tem = fold_ternary/*_to_constant*/ (res_op->code, res_op->type,
>-                                          res_op->ops[0], res_op->ops[1],
>-                                          res_op->ops[2]);
>+      {
>+        tree_code code = res_op->code;
>+        if (IS_EXPR_CODE_CLASS (TREE_CODE_CLASS (code))
>+            && TREE_CODE_LENGTH (code) == 3)
>+          tem = fold_ternary/*_to_constant*/ (res_op->code, res_op->type,
>+                                              res_op->ops[0], res_op->ops[1],
>+                                              res_op->ops[2]);
>+      }
>       else
>       tem = fold_const_call (combined_fn (res_op->code), res_op->type,
>                              res_op->ops[0], res_op->ops[1], res_op->ops[2]);
>--- gcc/testsuite/g++.dg/opt/pr92401.C.jj      2019-11-08 09:07:48.465767281
>+0100
>+++ gcc/testsuite/g++.dg/opt/pr92401.C 2019-11-08 09:26:02.778350689
>+0100
>@@ -0,0 +1,15 @@
>+// PR tree-optimization/92401
>+// { dg-do compile { target c++11 } }
>+// { dg-options "-O2" }
>+
>+typedef float V __attribute__ ((__vector_size__ (4 * sizeof
>(float))));
>+
>+V v;
>+
>+void
>+foo ()
>+{
>+  int i;
>+  for (i = 0; i < 11; ++i)
>+    v = V { 0.0f, 0.0f, (float) i, 0.0f };
>+}
>
>       Jakub

Reply via email to