]> gcc.gnu.org Git - gcc.git/commitdiff
tree-optimization/111614 - missing convert in undistribute_bitref_for_vector
authorRichard Biener <rguenther@suse.de>
Thu, 28 Sep 2023 07:41:30 +0000 (09:41 +0200)
committerRichard Biener <rguenther@suse.de>
Thu, 28 Sep 2023 09:22:47 +0000 (11:22 +0200)
The following adjusts a flawed guard for converting the first vector
of the sum we create in undistribute_bitref_for_vector.

PR tree-optimization/111614
* tree-ssa-reassoc.cc (undistribute_bitref_for_vector): Properly
convert the first vector when required.

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

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

diff --git a/gcc/testsuite/gcc.dg/torture/pr111614.c b/gcc/testsuite/gcc.dg/torture/pr111614.c
new file mode 100644 (file)
index 0000000..0f3ecba
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+
+int a, b, c, d, e;
+static void f() {
+  int *g = &b;
+  b = 1;
+  for (; b >= 0; b--) {
+    c = 0;
+    for (; c <= 1; c++)
+      e = 0;
+    for (; e <= 1; e++) {
+      int h, i = h = 13;
+      for (; h; h--)
+        i = i << a;
+      d &= i + c + 9 + *g;
+    }
+  }
+}
+int main() {
+  f();
+  for (;;)
+    ;
+}
index eda03bf98a6069c95f36867c323990d0e185c7e3..41ee36413b533b8ee1d2db95355933b8b9821ce1 100644 (file)
@@ -2102,12 +2102,24 @@ undistribute_bitref_for_vector (enum tree_code opcode,
        {
          sum = build_and_add_sum (vec_type, sum_vec,
                                   valid_vecs[i + 1], opcode);
+         /* Update the operands only after build_and_add_sum,
+            so that we don't have to repeat the placement algorithm
+            of build_and_add_sum.  */
+         if (sum_vec == tvec
+             && !useless_type_conversion_p (vec_type, TREE_TYPE (sum_vec)))
+           {
+             gimple_stmt_iterator gsi = gsi_for_stmt (sum);
+             tree vce = build1 (VIEW_CONVERT_EXPR, vec_type, sum_vec);
+             tree lhs = make_ssa_name (vec_type);
+             gimple *g = gimple_build_assign (lhs, VIEW_CONVERT_EXPR, vce);
+             gimple_set_uid (g, gimple_uid (sum));
+             gsi_insert_before (&gsi, g, GSI_NEW_STMT);
+             gimple_assign_set_rhs1 (sum, lhs);
+             update_stmt (sum);
+           }
          if (!useless_type_conversion_p (vec_type,
                                          TREE_TYPE (valid_vecs[i + 1])))
            {
-             /* Update the operands only after build_and_add_sum,
-                so that we don't have to repeat the placement algorithm
-                of build_and_add_sum.  */
              gimple_stmt_iterator gsi = gsi_for_stmt (sum);
              tree vce = build1 (VIEW_CONVERT_EXPR, vec_type,
                                 valid_vecs[i + 1]);
@@ -2116,15 +2128,6 @@ undistribute_bitref_for_vector (enum tree_code opcode,
              gimple_set_uid (g, gimple_uid (sum));
              gsi_insert_before (&gsi, g, GSI_NEW_STMT);
              gimple_assign_set_rhs2 (sum, lhs);
-             if (sum_vec == tvec)
-               {
-                 vce = build1 (VIEW_CONVERT_EXPR, vec_type, sum_vec);
-                 lhs = make_ssa_name (vec_type);
-                 g = gimple_build_assign (lhs, VIEW_CONVERT_EXPR, vce);
-                 gimple_set_uid (g, gimple_uid (sum));
-                 gsi_insert_before (&gsi, g, GSI_NEW_STMT);
-                 gimple_assign_set_rhs1 (sum, lhs);
-               }
              update_stmt (sum);
            }
          sum_vec = gimple_get_lhs (sum);
This page took 0.101089 seconds and 5 git commands to generate.