Skip to content

Commit 192e7d3

Browse files
committed
[IRBuilder] Add IsNonNeg param to CreateZExt() (NFC)
1 parent 9f265c3 commit 192e7d3

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,8 +1994,16 @@ class IRBuilderBase {
19941994
return CreateCast(Instruction::Trunc, V, DestTy, Name);
19951995
}
19961996

1997-
Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "") {
1998-
return CreateCast(Instruction::ZExt, V, DestTy, Name);
1997+
Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "",
1998+
bool IsNonNeg = false) {
1999+
if (V->getType() == DestTy)
2000+
return V;
2001+
if (Value *Folded = Folder.FoldCast(Instruction::ZExt, V, DestTy))
2002+
return Folded;
2003+
Instruction *I = Insert(new ZExtInst(V, DestTy), Name);
2004+
if (IsNonNeg)
2005+
I->setNonNeg();
2006+
return I;
19992007
}
20002008

20012009
Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,10 +1293,8 @@ Value *SCEVExpander::visitTruncateExpr(const SCEVTruncateExpr *S) {
12931293

12941294
Value *SCEVExpander::visitZeroExtendExpr(const SCEVZeroExtendExpr *S) {
12951295
Value *V = expand(S->getOperand());
1296-
auto *Res = Builder.CreateZExt(V, S->getType());
1297-
if (auto *I = dyn_cast<Instruction>(Res))
1298-
I->setNonNeg(SE.isKnownNonNegative(S->getOperand()));
1299-
return Res;
1296+
return Builder.CreateZExt(V, S->getType(), "",
1297+
SE.isKnownNonNegative(S->getOperand()));
13001298
}
13011299

13021300
Value *SCEVExpander::visitSignExtendExpr(const SCEVSignExtendExpr *S) {

0 commit comments

Comments
 (0)