[llvm] IRCE: Fix '"Instruction does not dominate all uses!" after IRCE pass #63984' (PR #136505)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 20 12:53:05 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: None (Zentrik)

<details>
<summary>Changes</summary>

upstream/main

---
Full diff: https://github.com/llvm/llvm-project/pull/136505.diff


1 Files Affected:

- (modified) llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp (+9-4) 


``````````diff
diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
index e706a6f83b1e7..4da816bea5870 100644
--- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
+++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
@@ -265,8 +265,13 @@ bool InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
                                               ScalarEvolution &SE,
                                               const SCEVAddRecExpr *&Index,
                                               const SCEV *&End) {
-  auto IsLoopInvariant = [&SE, L](Value *V) {
-    return SE.isLoopInvariant(SE.getSCEV(V), L);
+  auto IsLoopInvariantAndNotUndef = [&SE, L](Value *V) {
+    const SCEV *S = SE.getSCEV(V);
+
+    if (isa<SCEVCouldNotCompute>(S))
+      return false;
+
+    return SE.isLoopInvariant(SE.getSCEV(V), L) && !SE.containsUndefs(S);
   };
 
   ICmpInst::Predicate Pred = ICI->getPredicate();
@@ -277,10 +282,10 @@ bool InductiveRangeCheck::parseRangeCheckICmp(Loop *L, ICmpInst *ICI,
     return false;
 
   // Canonicalize to the `Index Pred Invariant` comparison
-  if (IsLoopInvariant(LHS)) {
+  if (IsLoopInvariantAndNotUndef(LHS)) {
     std::swap(LHS, RHS);
     Pred = CmpInst::getSwappedPredicate(Pred);
-  } else if (!IsLoopInvariant(RHS))
+  } else if (!IsLoopInvariantAndNotUndef(RHS))
     // Both LHS and RHS are loop variant
     return false;
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/136505


More information about the llvm-commits mailing list