[llvm] 192e7d3 - [IRBuilder] Add IsNonNeg param to CreateZExt() (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 10 03:00:42 PST 2023


Author: Nikita Popov
Date: 2023-11-10T12:00:34+01:00
New Revision: 192e7d3d5229fd97ce27c9dde63f6d36fba9048d

URL: https://github.com/llvm/llvm-project/commit/192e7d3d5229fd97ce27c9dde63f6d36fba9048d
DIFF: https://github.com/llvm/llvm-project/commit/192e7d3d5229fd97ce27c9dde63f6d36fba9048d.diff

LOG: [IRBuilder] Add IsNonNeg param to CreateZExt() (NFC)

Added: 
    

Modified: 
    llvm/include/llvm/IR/IRBuilder.h
    llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index c9f243fdb12e404..c263d310e444065 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -1994,8 +1994,16 @@ class IRBuilderBase {
     return CreateCast(Instruction::Trunc, V, DestTy, Name);
   }
 
-  Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "") {
-    return CreateCast(Instruction::ZExt, V, DestTy, Name);
+  Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "",
+                    bool IsNonNeg = false) {
+    if (V->getType() == DestTy)
+      return V;
+    if (Value *Folded = Folder.FoldCast(Instruction::ZExt, V, DestTy))
+      return Folded;
+    Instruction *I = Insert(new ZExtInst(V, DestTy), Name);
+    if (IsNonNeg)
+      I->setNonNeg();
+    return I;
   }
 
   Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {

diff  --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index c8cd9c4ee13e65c..8bfe9e67d15e2f9 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -1293,10 +1293,8 @@ Value *SCEVExpander::visitTruncateExpr(const SCEVTruncateExpr *S) {
 
 Value *SCEVExpander::visitZeroExtendExpr(const SCEVZeroExtendExpr *S) {
   Value *V = expand(S->getOperand());
-  auto *Res = Builder.CreateZExt(V, S->getType());
-  if (auto *I = dyn_cast<Instruction>(Res))
-    I->setNonNeg(SE.isKnownNonNegative(S->getOperand()));
-  return Res;
+  return Builder.CreateZExt(V, S->getType(), "",
+                            SE.isKnownNonNegative(S->getOperand()));
 }
 
 Value *SCEVExpander::visitSignExtendExpr(const SCEVSignExtendExpr *S) {


        


More information about the llvm-commits mailing list