re PR tree-optimization/92401 (ICE in fold_ternary_loc, at fold-const.c:11698)
authorJakub Jelinek <jakub@redhat.com>
Sat, 9 Nov 2019 17:09:44 +0000 (18:09 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 9 Nov 2019 17:09:44 +0000 (18:09 +0100)
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.

From-SVN: r278004

gcc/ChangeLog
gcc/gimple-match-head.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr92401.C [new file with mode: 0644]

index f82006ac08b78106feac83402326d6d5c0fe12e9..d0fe87e32671ef5687097520db73cb95c808fdd1 100644 (file)
@@ -1,3 +1,13 @@
+2019-11-09  Jakub Jelinek  <jakub@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.
+
 2019-11-09  Iain Sandoe  <iain@sandoe.co.uk>
 
        * config/darwin.c (machopic_mcount_stub_name): Validate the
index d7c74a1865ae4afc8c2da7a3d562a41b8242ccd8..2996bade301e09e433d9c415348a5b3fba882482 100644 (file)
@@ -191,7 +191,12 @@ gimple_resimplify1 (gimple_seq *seq, gimple_match_op *res_op,
     {
       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, gimple_match_op *res_op,
     {
       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, gimple_match_op *res_op,
     {
       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]);
index 0f8ef38320e072fbcc802cfe0425fccdb8977d0b..fcad98053bc626fdffb5a472a8c8011cdc541ee3 100644 (file)
@@ -1,3 +1,8 @@
+2019-11-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/92401
+       * g++.dg/opt/pr92401.C: New test.
+
 2019-11-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/92321
diff --git a/gcc/testsuite/g++.dg/opt/pr92401.C b/gcc/testsuite/g++.dg/opt/pr92401.C
new file mode 100644 (file)
index 0000000..fda9821
--- /dev/null
@@ -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 };
+}