diff options
author | Philip Reames <preames@rivosinc.com> | 2023-10-31 14:37:57 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-31 14:37:57 -0700 |
commit | a78f5c064975f4d597ed1b18206d579748eb91cb (patch) | |
tree | 5952b114319a1b9aeba14ed13ecde6d34955fc6a /llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | |
parent | 5bfd89bda7c2d5ff167c7bcea0c8d69b0b498f08 (diff) | |
download | llvm-a78f5c064975f4d597ed1b18206d579748eb91cb.zip llvm-a78f5c064975f4d597ed1b18206d579748eb91cb.tar.gz llvm-a78f5c064975f4d597ed1b18206d579748eb91cb.tar.bz2 |
[IndVars] Use IRBuilder in eliminateTrunc [nfc-ish] (#70836)
Mostly a cleanup so that we don't need to manually emit instructions,
and can eagerly constant fold where relevant.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyIndVar.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyIndVar.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp index a23ac41..ae36441 100644 --- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp @@ -539,7 +539,8 @@ bool SimplifyIndvar::eliminateTrunc(TruncInst *TI) { for (auto *ICI : ICmpUsers) { bool IsSwapped = L->isLoopInvariant(ICI->getOperand(0)); auto *Op1 = IsSwapped ? ICI->getOperand(0) : ICI->getOperand(1); - Instruction *Ext = nullptr; + IRBuilder<> Builder(ICI); + Value *Ext = nullptr; // For signed/unsigned predicate, replace the old comparison with comparison // of immediate IV against sext/zext of the invariant argument. If we can // use either sext or zext (i.e. we are dealing with equality predicate), @@ -550,18 +551,18 @@ bool SimplifyIndvar::eliminateTrunc(TruncInst *TI) { if (IsSwapped) Pred = ICmpInst::getSwappedPredicate(Pred); if (CanUseZExt(ICI)) { assert(DoesZExtCollapse && "Unprofitable zext?"); - Ext = new ZExtInst(Op1, IVTy, "zext", ICI); + Ext = Builder.CreateZExt(Op1, IVTy, "zext"); Pred = ICmpInst::getUnsignedPredicate(Pred); } else { assert(DoesSExtCollapse && "Unprofitable sext?"); - Ext = new SExtInst(Op1, IVTy, "sext", ICI); + Ext = Builder.CreateSExt(Op1, IVTy, "sext"); assert(Pred == ICmpInst::getSignedPredicate(Pred) && "Must be signed!"); } bool Changed; L->makeLoopInvariant(Ext, Changed); (void)Changed; - ICmpInst *NewICI = new ICmpInst(ICI, Pred, IV, Ext); - ICI->replaceAllUsesWith(NewICI); + auto *NewCmp = Builder.CreateICmp(Pred, IV, Ext); + ICI->replaceAllUsesWith(NewCmp); DeadInsts.emplace_back(ICI); } |