[llvm] aa47962 - [InstCombine] canNarrowShiftAmt - replace custom Constant matching with m_SpecificInt_ICMP
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 8 02:53:51 PDT 2020
Author: Simon Pilgrim
Date: 2020-10-08T10:53:32+01:00
New Revision: aa47962cc9493cd79ca78954e721ed02479729c7
URL: https://github.com/llvm/llvm-project/commit/aa47962cc9493cd79ca78954e721ed02479729c7
DIFF: https://github.com/llvm/llvm-project/commit/aa47962cc9493cd79ca78954e721ed02479729c7.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index edb2dc8881c7..c13362fa3136 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -1701,27 +1701,8 @@ static Instruction *foldOrToXor(BinaryOperator &I,
/// Return true if a constant shift amount is always less than the specified
/// bit-width. If not, the shift could create poison in the narrower type.
static bool canNarrowShiftAmt(Constant *C, unsigned BitWidth) {
- if (auto *ScalarC = dyn_cast<ConstantInt>(C))
- return ScalarC->getZExtValue() < BitWidth;
-
- if (C->getType()->isVectorTy()) {
- // Check each element of a constant vector.
- unsigned NumElts = cast<FixedVectorType>(C->getType())->getNumElements();
- for (unsigned i = 0; i != NumElts; ++i) {
- Constant *Elt = C->getAggregateElement(i);
- if (!Elt)
- return false;
- if (isa<UndefValue>(Elt))
- continue;
- auto *CI = dyn_cast<ConstantInt>(Elt);
- if (!CI || CI->getZExtValue() >= BitWidth)
- return false;
- }
- return true;
- }
-
- // The constant is a constant expression or unknown.
- return false;
+ APInt Threshold(C->getType()->getScalarSizeInBits(), BitWidth);
+ return match(C, m_SpecificInt_ICMP(ICmpInst::ICMP_ULT, Threshold));
}
/// Try to use narrower ops (sink zext ops) for an 'and' with binop operand and
More information about the llvm-commits
mailing list