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.
--- /dev/null
+/* { 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" } } */
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;