]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/111917 - bougs IL after guard hoisting
authorRichard Biener <rguenther@suse.de>
Mon, 23 Oct 2023 09:25:17 +0000 (11:25 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 27 Nov 2023 11:52:27 +0000 (12:52 +0100)
The unswitching code to hoist guards inserts conditions in wrong
places.  The following fixes this, simplifying code.

PR tree-optimization/111917
* tree-ssa-loop-unswitch.cc (hoist_guard): Always insert
new conditional after last stmt.

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

(cherry picked from commit d96bd4aade170fcd86f5f09b68b770dde798e631)

gcc/testsuite/gcc.dg/torture/pr111917.c [new file with mode: 0644]
gcc/tree-ssa-loop-unswitch.cc

diff --git a/gcc/testsuite/gcc.dg/torture/pr111917.c b/gcc/testsuite/gcc.dg/torture/pr111917.c
new file mode 100644 (file)
index 0000000..532e302
--- /dev/null
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-funswitch-loops" } */
+
+long t;
+long a() {
+  long b = t, c = t;
+  for (; b < 31; b++)
+    c <<= 1;
+  return c;
+}
+long t1;
+static
+int d() {
+  if (!t1)
+    return 0;
+e:
+f:
+  for (; a();)
+    ;
+  goto f;
+  return 0;
+}
+int main() { d(); }
index 2927f308234fde734de61f03adc583bdcb8e075c..a9be87c23308702c2f0491bce235a2a60f22cd2c 100644 (file)
@@ -839,10 +839,7 @@ hoist_guard (class loop *loop, edge guard)
   cond_stmt = as_a <gcond *> (stmt);
   extract_true_false_edges_from_block (guard_bb, &te, &fe);
   /* Insert guard to PRE_HEADER.  */
-  if (!empty_block_p (pre_header))
-    gsi = gsi_last_bb (pre_header);
-  else
-    gsi = gsi_start_bb (pre_header);
+  gsi = gsi_last_bb (pre_header);
   /* Create copy of COND_STMT.  */
   new_cond_stmt = gimple_build_cond (gimple_cond_code (cond_stmt),
                                     gimple_cond_lhs (cond_stmt),