Skip to content

Commit aa47962

Browse files
committed
[InstCombine] canNarrowShiftAmt - replace custom Constant matching with m_SpecificInt_ICMP
The existing code ignores undef values which matches m_SpecificInt_ICMP, although m_SpecificInt_ICMP returns false for an all-undef constant, I've added test coverage at rGfe0197e194a64f9 to show that undef folding should already have dealt with that case.
1 parent cc83dc1 commit aa47962

File tree

1 file changed

+2
-21
lines changed

1 file changed

+2
-21
lines changed

llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,27 +1701,8 @@ static Instruction *foldOrToXor(BinaryOperator &I,
17011701
/// Return true if a constant shift amount is always less than the specified
17021702
/// bit-width. If not, the shift could create poison in the narrower type.
17031703
static bool canNarrowShiftAmt(Constant *C, unsigned BitWidth) {
1704-
if (auto *ScalarC = dyn_cast<ConstantInt>(C))
1705-
return ScalarC->getZExtValue() < BitWidth;
1706-
1707-
if (C->getType()->isVectorTy()) {
1708-
// Check each element of a constant vector.
1709-
unsigned NumElts = cast<FixedVectorType>(C->getType())->getNumElements();
1710-
for (unsigned i = 0; i != NumElts; ++i) {
1711-
Constant *Elt = C->getAggregateElement(i);
1712-
if (!Elt)
1713-
return false;
1714-
if (isa<UndefValue>(Elt))
1715-
continue;
1716-
auto *CI = dyn_cast<ConstantInt>(Elt);
1717-
if (!CI || CI->getZExtValue() >= BitWidth)
1718-
return false;
1719-
}
1720-
return true;
1721-
}
1722-
1723-
// The constant is a constant expression or unknown.
1724-
return false;
1704+
APInt Threshold(C->getType()->getScalarSizeInBits(), BitWidth);
1705+
return match(C, m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, Threshold));
17251706
}
17261707

17271708
/// Try to use narrower ops (sink zext ops) for an 'and' with binop operand and

0 commit comments

Comments
 (0)