Skip to content

Commit 440af98

Browse files
committed
[InstCombine] Avoid use of ConstantExpr::getShl()
Use IRBuilder instead. Also use ImmConstant to guarantee that this will fold.
1 parent 552f80a commit 440af98

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -749,18 +749,18 @@ Instruction *InstCombinerImpl::visitTrunc(TruncInst &Trunc) {
749749
}
750750

751751
Constant *C;
752-
if (match(Src, m_OneUse(m_LShr(m_Value(X), m_Constant(C))))) {
752+
if (match(Src, m_OneUse(m_LShr(m_Value(X), m_ImmConstant(C))))) {
753753
// trunc (lshr X, C) to i1 --> icmp ne (and X, C'), 0
754754
Constant *One = ConstantInt::get(SrcTy, APInt(SrcWidth, 1));
755-
Constant *MaskC = ConstantExpr::getShl(One, C);
755+
Value *MaskC = Builder.CreateShl(One, C);
756756
Value *And = Builder.CreateAnd(X, MaskC);
757757
return new ICmpInst(ICmpInst::ICMP_NE, And, Zero);
758758
}
759759
if (match(Src, m_OneUse(m_c_Or(m_LShr(m_Value(X), m_ImmConstant(C)),
760760
m_Deferred(X))))) {
761761
// trunc (or (lshr X, C), X) to i1 --> icmp ne (and X, C'), 0
762762
Constant *One = ConstantInt::get(SrcTy, APInt(SrcWidth, 1));
763-
Constant *MaskC = ConstantExpr::getShl(One, C);
763+
Value *MaskC = Builder.CreateShl(One, C);
764764
Value *And = Builder.CreateAnd(X, Builder.CreateOr(MaskC, One));
765765
return new ICmpInst(ICmpInst::ICMP_NE, And, Zero);
766766
}

0 commit comments

Comments
 (0)