]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
tree-optimization/124947 - IVOPTs emits uninit use
authorRichard Biener <rguenther@suse.de>
Tue, 21 Apr 2026 08:21:34 +0000 (10:21 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 24 Apr 2026 07:09:11 +0000 (09:09 +0200)
The following prevents IVOPTs from rewriting a compare using an IV
that involves undefined SSA vars.

PR tree-optimization/124947
* tree-ssa-loop-ivopts.cc (may_eliminate_iv): Do not use
a candidate that involves undefs.

* gcc.dg/pr124947.c: New testcase.

gcc/testsuite/gcc.dg/pr124947.c [new file with mode: 0644]
gcc/tree-ssa-loop-ivopts.cc

diff --git a/gcc/testsuite/gcc.dg/pr124947.c b/gcc/testsuite/gcc.dg/pr124947.c
new file mode 100644 (file)
index 0000000..5e64d29
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-options "-O -fdump-tree-ivopts" } */
+
+long *BN_uadd_ap;
+
+void
+BN_uadd (int dif, long t1)
+{
+  volatile long *rp;
+  while (dif)
+    {
+      dif--;
+      t1 = *BN_uadd_ap;
+      *rp++ = t1;
+      if (t1)
+        break;
+    }
+}
+
+/* { dg-final { scan-tree-dump-times "rp_\[0-9\]+\\\(D\\\)" 1 "ivopts" } } */
index 6ecf5bef7b4fabc8daf2110def0d09128b57ec01..dfec607fd2eb118905bf4d9a8d7207e45e0424cc 100644 (file)
@@ -5382,6 +5382,11 @@ may_eliminate_iv (struct ivopts_data *data,
   aff_tree bnd;
   class tree_niter_desc *desc = NULL;
 
+  /* If the IV candidate involves undefs do not attempt to use it to
+     express a condition.  */
+  if (cand->involves_undefs)
+    return false;
+
   if (TREE_CODE (cand->iv->step) != INTEGER_CST)
     return false;