[llvm] [InstCombine] Avoid rewriting multi-use post-inc latch icmps (preserve nsw/nuw for later passes) (PR #215960)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 12 23:14:39 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- llvm/include/llvm/Analysis/ScalarEvolution.h llvm/lib/Analysis/ScalarEvolution.cpp llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 93564d989..40ce90643 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -9593,9 +9593,8 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromICmp(
return EL;
// X < (Y+1) failed to get an exact count. Try the pre-inc form.
- ExitLimit PreEL = howManyLessThansViaPreInc(OrigLHS, OrigRHS, L, IsSigned,
- ControlsOnlyExit,
- AllowPredicates);
+ ExitLimit PreEL = howManyLessThansViaPreInc(
+ OrigLHS, OrigRHS, L, IsSigned, ControlsOnlyExit, AllowPredicates);
if (PreEL.hasFullInfo())
return PreEL;
@@ -9618,10 +9617,9 @@ ScalarEvolution::ExitLimit ScalarEvolution::computeExitLimitFromICmp(
// SimplifyICmpOperands may have rewritten an original X <= Y into
// X < (Y + 1). Retry with the pre-inc form of the original compare.
if (OrigPred == ICmpInst::ICMP_ULE || OrigPred == ICmpInst::ICMP_SLE) {
- ExitLimit PreEL = howManyLessThansViaPreInc(OrigLHS, OrigRHS, L,
- ICmpInst::isSigned(OrigPred),
- ControlsOnlyExit,
- AllowPredicates);
+ ExitLimit PreEL = howManyLessThansViaPreInc(
+ OrigLHS, OrigRHS, L, ICmpInst::isSigned(OrigPred), ControlsOnlyExit,
+ AllowPredicates);
if (PreEL.hasFullInfo())
return PreEL;
if (!EL.hasAnyInfo() && PreEL.hasAnyInfo())
@@ -13438,8 +13436,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::howManyLessThansViaPreInc(
return getCouldNotCompute();
const auto *AR = dyn_cast<SCEVAddRecExpr>(LHS);
- SCEV::NoWrapFlags NoWrapFlag =
- IsSigned ? SCEV::FlagNSW : SCEV::FlagNUW;
+ SCEV::NoWrapFlags NoWrapFlag = IsSigned ? SCEV::FlagNSW : SCEV::FlagNUW;
if (!AR || AR->getLoop() != L || !AR->isAffine() ||
!AR->getNoWrapFlags(NoWrapFlag))
return getCouldNotCompute();
@@ -13452,8 +13449,7 @@ ScalarEvolution::ExitLimit ScalarEvolution::howManyLessThansViaPreInc(
const SCEV *PreStart = getMinusSCEV(AR->getStart(), Step);
// Do not transfer nowrap flags from the post-inc AddRec to its sibling.
- const SCEV *PreAR =
- getAddRecExpr(PreStart, Step, L, SCEV::FlagAnyWrap);
+ const SCEV *PreAR = getAddRecExpr(PreStart, Step, L, SCEV::FlagAnyWrap);
const APInt &StepV = StepC->getAPInt();
auto IsMultipleOfStep = [&](const SCEV *S) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/215960
More information about the llvm-commits
mailing list