aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
diff options
context:
space:
mode:
authorRamkumar Ramachandra <ramkumar.ramachandra@codasip.com>2025-02-06 11:13:01 +0000
committerGitHub <noreply@github.com>2025-02-06 11:13:01 +0000
commitd0f472c246911e35656bf24fd282f80d7482211a (patch)
tree15993cd6241d2a30b8a12458562752e787d8c126 /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
parent7ebacf3a999fc9766c3f0ec4979e3ed08344c348 (diff)
downloadllvm-d0f472c246911e35656bf24fd282f80d7482211a.zip
llvm-d0f472c246911e35656bf24fd282f80d7482211a.tar.gz
llvm-d0f472c246911e35656bf24fd282f80d7482211a.tar.bz2
SimplifyIndVar: teach widenLoopCompare about samesign (#125851)
Proof: https://alive2.llvm.org/ce/z/NVXaeo
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyIndVar.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index e41a1ad..7b9c5c7 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -1614,7 +1614,8 @@ bool WidenIV::widenLoopCompare(WidenIV::NarrowIVDefUse DU) {
// (A) == icmp slt i32 sext(%narrow), sext(%val)
// == icmp slt i32 zext(%narrow), sext(%val)
bool IsSigned = getExtendKind(DU.NarrowDef) == ExtendKind::Sign;
- if (!(DU.NeverNegative || IsSigned == Cmp->isSigned()))
+ bool CmpPreferredSign = Cmp->hasSameSign() ? IsSigned : Cmp->isSigned();
+ if (!DU.NeverNegative && IsSigned != CmpPreferredSign)
return false;
Value *Op = Cmp->getOperand(Cmp->getOperand(0) == DU.NarrowDef ? 1 : 0);
@@ -1627,7 +1628,7 @@ bool WidenIV::widenLoopCompare(WidenIV::NarrowIVDefUse DU) {
// Widen the other operand of the compare, if necessary.
if (CastWidth < IVWidth) {
- Value *ExtOp = createExtendInst(Op, WideType, Cmp->isSigned(), Cmp);
+ Value *ExtOp = createExtendInst(Op, WideType, CmpPreferredSign, Cmp);
DU.NarrowUse->replaceUsesOfWith(Op, ExtOp);
}
return true;