[llvm] 702ccb4 - [InstCombine] getLogBase2(undef) -> 0.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 10 12:32:57 PDT 2020
Author: Simon Pilgrim
Date: 2020-10-10T20:29:03+01:00
New Revision: 702ccb40e2d7e832ff6dce84007b82e764f116ac
URL: https://github.com/llvm/llvm-project/commit/702ccb40e2d7e832ff6dce84007b82e764f116ac
DIFF: https://github.com/llvm/llvm-project/commit/702ccb40e2d7e832ff6dce84007b82e764f116ac.diff
LOG: [InstCombine] getLogBase2(undef) -> 0.
Move the undef element handling into the getLogBase2 helper instead of pre-empting with replaceUndefsWith.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index e97f8859d86f..e9b57cf38ef1 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -99,11 +99,9 @@ static Value *simplifyValueKnownNonZero(Value *V, InstCombinerImpl &IC,
///
/// If C is a scalar/fixed width vector of known powers of 2, then this
/// function returns a new scalar/fixed width vector obtained from logBase2
-/// of C.
+/// of C. Undef elements in a vector are set to zero.
/// Return a null pointer otherwise.
static Constant *getLogBase2(Constant *C) {
- // Note that log2(iN undef) is *NOT* iN undef, because log2(iN undef) u< N.
- // FIXME: just assert that C there is no undef in \p C.
Type *Ty = C->getType();
const APInt *IVal;
if (match(C, m_APInt(IVal)) && IVal->isPowerOf2())
@@ -119,8 +117,9 @@ static Constant *getLogBase2(Constant *C) {
Constant *Elt = C->getAggregateElement(I);
if (!Elt)
return nullptr;
+ // Note that log2(iN undef) is *NOT* iN undef, because log2(iN undef) u< N.
if (isa<UndefValue>(Elt)) {
- Elts.push_back(UndefValue::get(Ty->getScalarType()));
+ Elts.push_back(Constant::getNullValue(Ty->getScalarType()));
continue;
}
if (!match(Elt, m_APInt(IVal)) || !IVal->isPowerOf2())
@@ -220,11 +219,7 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
if (match(&I, m_Mul(m_Value(NewOp), m_Constant(C1)))) {
// Replace X*(2^C) with X << C, where C is either a scalar or a vector.
- // Note that we need to sanitize undef multipliers to 1,
- // to avoid introducing poison.
- Constant *SafeC1 = Constant::replaceUndefsWith(
- C1, ConstantInt::get(C1->getType()->getScalarType(), 1));
- if (Constant *NewCst = getLogBase2(SafeC1)) {
+ if (Constant *NewCst = getLogBase2(C1)) {
BinaryOperator *Shl = BinaryOperator::CreateShl(NewOp, NewCst);
if (I.hasNoUnsignedWrap())
More information about the llvm-commits
mailing list