Skip to content

Commit fe32b6f

Browse files
committed
support cases where rhs are equal
1 parent 2930936 commit fe32b6f

File tree

2 files changed

+89
-116
lines changed

2 files changed

+89
-116
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,14 +1888,23 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
18881888
return I;
18891889
}
18901890

1891-
// umax(nuw_shl(base, x), nuw_shl(base, y)) -> nuw_shl(base, umax(x, y))
1892-
// umin(nuw_shl(base, x), nuw_shl(base, y)) -> nuw_shl(base, umin(x, y))
1893-
Value *Base;
1894-
Value *Shamt1, *Shamt2;
1895-
if (match(I0, m_OneUse(m_NUWShl(m_Value(Base), m_Value(Shamt1)))) &&
1896-
match(I1, m_OneUse(m_NUWShl(m_Deferred(Base), m_Value(Shamt2))))) {
1897-
Value *MaxMin = Builder.CreateBinaryIntrinsic(IID, Shamt1, Shamt2);
1898-
auto *NewShl = BinaryOperator::CreateNUWShl(Base, MaxMin);
1891+
Value *CommonShlOperand;
1892+
BinaryOperator *NewShl = nullptr;
1893+
// umax(nuw_shl(z, x), nuw_shl(z, y)) -> nuw_shl(z, umax(x, y))
1894+
// umin(nuw_shl(z, x), nuw_shl(z, y)) -> nuw_shl(z, umin(x, y))
1895+
if (match(I0, m_OneUse(m_NUWShl(m_Value(CommonShlOperand), m_Value(X)))) &&
1896+
match(I1,
1897+
m_OneUse(m_NUWShl(m_Deferred(CommonShlOperand), m_Value(Y))))) {
1898+
Value *MaxMin = Builder.CreateBinaryIntrinsic(IID, X, Y);
1899+
NewShl = BinaryOperator::CreateNUWShl(CommonShlOperand, MaxMin);
1900+
} else if (match(I0, m_OneUse(m_NUWShl(m_Value(X),
1901+
m_Value(CommonShlOperand)))) &&
1902+
match(I1, m_OneUse(m_NUWShl(m_Value(Y),
1903+
m_Deferred(CommonShlOperand))))) {
1904+
Value *MaxMin = Builder.CreateBinaryIntrinsic(IID, X, Y);
1905+
NewShl = BinaryOperator::CreateNUWShl(MaxMin, CommonShlOperand);
1906+
}
1907+
if (NewShl) {
18991908
if (cast<BinaryOperator>(I0)->hasNoSignedWrap() &&
19001909
cast<BinaryOperator>(I1)->hasNoSignedWrap())
19011910
NewShl->setHasNoSignedWrap();

0 commit comments

Comments
 (0)