Skip to content

Commit 1b8fb1a

Browse files
committed
[InstCombine] Avoid some uses of ConstantExpr::getZExt() (NFC)
Let the IRBuilder constant fold instead.
1 parent d8f530d commit 1b8fb1a

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,15 +830,15 @@ static Instruction *foldNoWrapAdd(BinaryOperator &Add,
830830
// (sext (X +nsw NarrowC)) + C --> (sext X) + (sext(NarrowC) + C)
831831
Constant *NarrowC;
832832
if (match(Op0, m_OneUse(m_SExt(m_NSWAdd(m_Value(X), m_Constant(NarrowC)))))) {
833-
Constant *WideC = ConstantExpr::getSExt(NarrowC, Ty);
834-
Constant *NewC = ConstantExpr::getAdd(WideC, Op1C);
833+
Value *WideC = Builder.CreateSExt(NarrowC, Ty);
834+
Value *NewC = Builder.CreateAdd(WideC, Op1C);
835835
Value *WideX = Builder.CreateSExt(X, Ty);
836836
return BinaryOperator::CreateAdd(WideX, NewC);
837837
}
838838
// (zext (X +nuw NarrowC)) + C --> (zext X) + (zext(NarrowC) + C)
839839
if (match(Op0, m_OneUse(m_ZExt(m_NUWAdd(m_Value(X), m_Constant(NarrowC)))))) {
840-
Constant *WideC = ConstantExpr::getZExt(NarrowC, Ty);
841-
Constant *NewC = ConstantExpr::getAdd(WideC, Op1C);
840+
Value *WideC = Builder.CreateZExt(NarrowC, Ty);
841+
Value *NewC = Builder.CreateAdd(WideC, Op1C);
842842
Value *WideX = Builder.CreateZExt(X, Ty);
843843
return BinaryOperator::CreateAdd(WideX, NewC);
844844
}

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,14 +1184,14 @@ Instruction *InstCombinerImpl::visitZExt(ZExtInst &Zext) {
11841184
Value *X;
11851185
if (match(Src, m_OneUse(m_And(m_Trunc(m_Value(X)), m_Constant(C)))) &&
11861186
X->getType() == DestTy)
1187-
return BinaryOperator::CreateAnd(X, ConstantExpr::getZExt(C, DestTy));
1187+
return BinaryOperator::CreateAnd(X, Builder.CreateZExt(C, DestTy));
11881188

11891189
// zext((trunc(X) & C) ^ C) -> ((X & zext(C)) ^ zext(C)).
11901190
Value *And;
11911191
if (match(Src, m_OneUse(m_Xor(m_Value(And), m_Constant(C)))) &&
11921192
match(And, m_OneUse(m_And(m_Trunc(m_Value(X)), m_Specific(C)))) &&
11931193
X->getType() == DestTy) {
1194-
Constant *ZC = ConstantExpr::getZExt(C, DestTy);
1194+
Value *ZC = Builder.CreateZExt(C, DestTy);
11951195
return BinaryOperator::CreateXor(Builder.CreateAnd(X, ZC), ZC);
11961196
}
11971197

@@ -1202,7 +1202,7 @@ Instruction *InstCombinerImpl::visitZExt(ZExtInst &Zext) {
12021202
// zext (and (trunc X), C) --> and X, (zext C)
12031203
if (match(Src, m_And(m_Trunc(m_Value(X)), m_Constant(C))) &&
12041204
X->getType() == DestTy) {
1205-
Constant *ZextC = ConstantExpr::getZExt(C, DestTy);
1205+
Value *ZextC = Builder.CreateZExt(C, DestTy);
12061206
return BinaryOperator::CreateAnd(X, ZextC);
12071207
}
12081208

0 commit comments

Comments
 (0)