[PATCH] D111836: [indvars] Use fact loop must exit to canonicalize to unsigned conditions
Max Kazantsev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 15 00:10:43 PDT 2021
mkazantsev added inline comments.
================
Comment at: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1425
+ return false;
+ auto *BI = dyn_cast<BranchInst>(ExitingBB->getTerminator());
+ if (!BI || BI->isUnconditional())
----------------
Looks like a great place to use pattern matching.
================
Comment at: llvm/test/Transforms/IndVarSimplify/finite-exit-comparisons.ll:304
; CHECK-NEXT: [[ZEXT:%.*]] = zext i8 [[IV_NEXT]] to i16
-; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i16 [[ZEXT]], 254
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i16 [[ZEXT]], 254
; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_END:%.*]]
----------------
Why does it need mustprogress notion to do this at all? Zext is non-negative, 254 is non-negative, we can always do that regardless of mustprogress. We have this logic in `eliminateIVComparison`:
```
} else if (ICmpInst::isSigned(OriginalPred) &&
SE->isKnownNonNegative(S) && SE->isKnownNonNegative(X)) {
// If we were unable to make anything above, all we can is to canonicalize
// the comparison hoping that it will open the doors for other
// optimizations. If we find out that we compare two non-negative values,
// we turn the instruction's predicate to its unsigned version. Note that
// we cannot rely on Pred here unless we check if we have swapped it.
assert(ICmp->getPredicate() == OriginalPred && "Predicate changed?");
LLVM_DEBUG(dbgs() << "INDVARS: Turn to unsigned comparison: " << *ICmp
<< '\n');
ICmp->setPredicate(ICmpInst::getUnsignedPredicate(OriginalPred));
```
Why it didn't work?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D111836/new/
https://reviews.llvm.org/D111836
More information about the llvm-commits
mailing list