aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp134
1 files changed, 67 insertions, 67 deletions
diff --git a/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 846116a929b1..a8a5f9831e15 100644
--- a/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/contrib/llvm-project/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -1319,8 +1319,8 @@ Value *InstCombinerImpl::simplifyShrShlDemandedBits(
}
/// The specified value produces a vector with any number of elements.
-/// This method analyzes which elements of the operand are undef or poison and
-/// returns that information in UndefElts.
+/// This method analyzes which elements of the operand are poison and
+/// returns that information in PoisonElts.
///
/// DemandedElts contains the set of elements that are actually used by the
/// caller, and by default (AllowMultipleUsers equals false) the value is
@@ -1333,7 +1333,7 @@ Value *InstCombinerImpl::simplifyShrShlDemandedBits(
/// returned. This returns null if no change was made.
Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
APInt DemandedElts,
- APInt &UndefElts,
+ APInt &PoisonElts,
unsigned Depth,
bool AllowMultipleUsers) {
// Cannot analyze scalable type. The number of vector elements is not a
@@ -1345,18 +1345,18 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
APInt EltMask(APInt::getAllOnes(VWidth));
assert((DemandedElts & ~EltMask) == 0 && "Invalid DemandedElts!");
- if (match(V, m_Undef())) {
- // If the entire vector is undef or poison, just return this info.
- UndefElts = EltMask;
+ if (match(V, m_Poison())) {
+ // If the entire vector is poison, just return this info.
+ PoisonElts = EltMask;
return nullptr;
}
if (DemandedElts.isZero()) { // If nothing is demanded, provide poison.
- UndefElts = EltMask;
+ PoisonElts = EltMask;
return PoisonValue::get(V->getType());
}
- UndefElts = 0;
+ PoisonElts = 0;
if (auto *C = dyn_cast<Constant>(V)) {
// Check if this is identity. If so, return 0 since we are not simplifying
@@ -1370,7 +1370,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
for (unsigned i = 0; i != VWidth; ++i) {
if (!DemandedElts[i]) { // If not demanded, set to poison.
Elts.push_back(Poison);
- UndefElts.setBit(i);
+ PoisonElts.setBit(i);
continue;
}
@@ -1378,8 +1378,8 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
if (!Elt) return nullptr;
Elts.push_back(Elt);
- if (isa<UndefValue>(Elt)) // Already undef or poison.
- UndefElts.setBit(i);
+ if (isa<PoisonValue>(Elt)) // Already poison.
+ PoisonElts.setBit(i);
}
// If we changed the constant, return it.
@@ -1400,7 +1400,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
// They'll be handled when it's their turn to be visited by
// the main instcombine process.
if (Depth != 0)
- // TODO: Just compute the UndefElts information recursively.
+ // TODO: Just compute the PoisonElts information recursively.
return nullptr;
// Conservatively assume that all elements are needed.
@@ -1422,8 +1422,8 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
}
};
- APInt UndefElts2(VWidth, 0);
- APInt UndefElts3(VWidth, 0);
+ APInt PoisonElts2(VWidth, 0);
+ APInt PoisonElts3(VWidth, 0);
switch (I->getOpcode()) {
default: break;
@@ -1449,17 +1449,17 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
if (i == 0 ? match(I->getOperand(i), m_Undef())
: match(I->getOperand(i), m_Poison())) {
// If the entire vector is undefined, just return this info.
- UndefElts = EltMask;
+ PoisonElts = EltMask;
return nullptr;
}
if (I->getOperand(i)->getType()->isVectorTy()) {
- APInt UndefEltsOp(VWidth, 0);
- simplifyAndSetOp(I, i, DemandedElts, UndefEltsOp);
+ APInt PoisonEltsOp(VWidth, 0);
+ simplifyAndSetOp(I, i, DemandedElts, PoisonEltsOp);
// gep(x, undef) is not undef, so skip considering idx ops here
// Note that we could propagate poison, but we can't distinguish between
// undef & poison bits ATM
if (i == 0)
- UndefElts |= UndefEltsOp;
+ PoisonElts |= PoisonEltsOp;
}
}
@@ -1472,7 +1472,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
if (!Idx) {
// Note that we can't propagate undef elt info, because we don't know
// which elt is getting updated.
- simplifyAndSetOp(I, 0, DemandedElts, UndefElts2);
+ simplifyAndSetOp(I, 0, DemandedElts, PoisonElts2);
break;
}
@@ -1487,7 +1487,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
// was extracted from the same index in another vector with the same type,
// replace this insert with that other vector.
// Note: This is attempted before the call to simplifyAndSetOp because that
- // may change UndefElts to a value that does not match with Vec.
+ // may change PoisonElts to a value that does not match with Vec.
Value *Vec;
if (PreInsertDemandedElts == 0 &&
match(I->getOperand(1),
@@ -1496,7 +1496,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
return Vec;
}
- simplifyAndSetOp(I, 0, PreInsertDemandedElts, UndefElts);
+ simplifyAndSetOp(I, 0, PreInsertDemandedElts, PoisonElts);
// If this is inserting an element that isn't demanded, remove this
// insertelement.
@@ -1506,7 +1506,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
}
// The inserted element is defined.
- UndefElts.clearBit(IdxNo);
+ PoisonElts.clearBit(IdxNo);
break;
}
case Instruction::ShuffleVector: {
@@ -1520,17 +1520,17 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
// operand.
if (all_of(Shuffle->getShuffleMask(), [](int Elt) { return Elt == 0; }) &&
DemandedElts.isAllOnes()) {
- if (!match(I->getOperand(1), m_Undef())) {
+ if (!isa<PoisonValue>(I->getOperand(1))) {
I->setOperand(1, PoisonValue::get(I->getOperand(1)->getType()));
MadeChange = true;
}
APInt LeftDemanded(OpWidth, 1);
- APInt LHSUndefElts(OpWidth, 0);
- simplifyAndSetOp(I, 0, LeftDemanded, LHSUndefElts);
- if (LHSUndefElts[0])
- UndefElts = EltMask;
+ APInt LHSPoisonElts(OpWidth, 0);
+ simplifyAndSetOp(I, 0, LeftDemanded, LHSPoisonElts);
+ if (LHSPoisonElts[0])
+ PoisonElts = EltMask;
else
- UndefElts.clearAllBits();
+ PoisonElts.clearAllBits();
break;
}
@@ -1549,11 +1549,11 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
}
}
- APInt LHSUndefElts(OpWidth, 0);
- simplifyAndSetOp(I, 0, LeftDemanded, LHSUndefElts);
+ APInt LHSPoisonElts(OpWidth, 0);
+ simplifyAndSetOp(I, 0, LeftDemanded, LHSPoisonElts);
- APInt RHSUndefElts(OpWidth, 0);
- simplifyAndSetOp(I, 1, RightDemanded, RHSUndefElts);
+ APInt RHSPoisonElts(OpWidth, 0);
+ simplifyAndSetOp(I, 1, RightDemanded, RHSPoisonElts);
// If this shuffle does not change the vector length and the elements
// demanded by this shuffle are an identity mask, then this shuffle is
@@ -1579,7 +1579,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
return Shuffle->getOperand(0);
}
- bool NewUndefElts = false;
+ bool NewPoisonElts = false;
unsigned LHSIdx = -1u, LHSValIdx = -1u;
unsigned RHSIdx = -1u, RHSValIdx = -1u;
bool LHSUniform = true;
@@ -1587,23 +1587,23 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
for (unsigned i = 0; i < VWidth; i++) {
unsigned MaskVal = Shuffle->getMaskValue(i);
if (MaskVal == -1u) {
- UndefElts.setBit(i);
+ PoisonElts.setBit(i);
} else if (!DemandedElts[i]) {
- NewUndefElts = true;
- UndefElts.setBit(i);
+ NewPoisonElts = true;
+ PoisonElts.setBit(i);
} else if (MaskVal < OpWidth) {
- if (LHSUndefElts[MaskVal]) {
- NewUndefElts = true;
- UndefElts.setBit(i);
+ if (LHSPoisonElts[MaskVal]) {
+ NewPoisonElts = true;
+ PoisonElts.setBit(i);
} else {
LHSIdx = LHSIdx == -1u ? i : OpWidth;
LHSValIdx = LHSValIdx == -1u ? MaskVal : OpWidth;
LHSUniform = LHSUniform && (MaskVal == i);
}
} else {
- if (RHSUndefElts[MaskVal - OpWidth]) {
- NewUndefElts = true;
- UndefElts.setBit(i);
+ if (RHSPoisonElts[MaskVal - OpWidth]) {
+ NewPoisonElts = true;
+ PoisonElts.setBit(i);
} else {
RHSIdx = RHSIdx == -1u ? i : OpWidth;
RHSValIdx = RHSValIdx == -1u ? MaskVal - OpWidth : OpWidth;
@@ -1646,11 +1646,11 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
return New;
}
}
- if (NewUndefElts) {
+ if (NewPoisonElts) {
// Add additional discovered undefs.
SmallVector<int, 16> Elts;
for (unsigned i = 0; i < VWidth; ++i) {
- if (UndefElts[i])
+ if (PoisonElts[i])
Elts.push_back(PoisonMaskElem);
else
Elts.push_back(Shuffle->getMaskValue(i));
@@ -1665,12 +1665,12 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
// on the current demanded elements.
SelectInst *Sel = cast<SelectInst>(I);
if (Sel->getCondition()->getType()->isVectorTy()) {
- // TODO: We are not doing anything with UndefElts based on this call.
+ // TODO: We are not doing anything with PoisonElts based on this call.
// It is overwritten below based on the other select operands. If an
// element of the select condition is known undef, then we are free to
// choose the output value from either arm of the select. If we know that
// one of those values is undef, then the output can be undef.
- simplifyAndSetOp(I, 0, DemandedElts, UndefElts);
+ simplifyAndSetOp(I, 0, DemandedElts, PoisonElts);
}
// Next, see if we can transform the arms of the select.
@@ -1692,12 +1692,12 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
}
}
- simplifyAndSetOp(I, 1, DemandedLHS, UndefElts2);
- simplifyAndSetOp(I, 2, DemandedRHS, UndefElts3);
+ simplifyAndSetOp(I, 1, DemandedLHS, PoisonElts2);
+ simplifyAndSetOp(I, 2, DemandedRHS, PoisonElts3);
// Output elements are undefined if the element from each arm is undefined.
// TODO: This can be improved. See comment in select condition handling.
- UndefElts = UndefElts2 & UndefElts3;
+ PoisonElts = PoisonElts2 & PoisonElts3;
break;
}
case Instruction::BitCast: {
@@ -1706,7 +1706,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
if (!VTy) break;
unsigned InVWidth = cast<FixedVectorType>(VTy)->getNumElements();
APInt InputDemandedElts(InVWidth, 0);
- UndefElts2 = APInt(InVWidth, 0);
+ PoisonElts2 = APInt(InVWidth, 0);
unsigned Ratio;
if (VWidth == InVWidth) {
@@ -1735,25 +1735,25 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
break;
}
- simplifyAndSetOp(I, 0, InputDemandedElts, UndefElts2);
+ simplifyAndSetOp(I, 0, InputDemandedElts, PoisonElts2);
if (VWidth == InVWidth) {
- UndefElts = UndefElts2;
+ PoisonElts = PoisonElts2;
} else if ((VWidth % InVWidth) == 0) {
// If the number of elements in the output is a multiple of the number of
// elements in the input then an output element is undef if the
// corresponding input element is undef.
for (unsigned OutIdx = 0; OutIdx != VWidth; ++OutIdx)
- if (UndefElts2[OutIdx / Ratio])
- UndefElts.setBit(OutIdx);
+ if (PoisonElts2[OutIdx / Ratio])
+ PoisonElts.setBit(OutIdx);
} else if ((InVWidth % VWidth) == 0) {
// If the number of elements in the input is a multiple of the number of
// elements in the output then an output element is undef if all of the
// corresponding input elements are undef.
for (unsigned OutIdx = 0; OutIdx != VWidth; ++OutIdx) {
- APInt SubUndef = UndefElts2.lshr(OutIdx * Ratio).zextOrTrunc(Ratio);
+ APInt SubUndef = PoisonElts2.lshr(OutIdx * Ratio).zextOrTrunc(Ratio);
if (SubUndef.popcount() == Ratio)
- UndefElts.setBit(OutIdx);
+ PoisonElts.setBit(OutIdx);
}
} else {
llvm_unreachable("Unimp");
@@ -1762,7 +1762,7 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
}
case Instruction::FPTrunc:
case Instruction::FPExt:
- simplifyAndSetOp(I, 0, DemandedElts, UndefElts);
+ simplifyAndSetOp(I, 0, DemandedElts, PoisonElts);
break;
case Instruction::Call: {
@@ -1785,18 +1785,18 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
DemandedPassThrough.clearBit(i);
}
if (II->getIntrinsicID() == Intrinsic::masked_gather)
- simplifyAndSetOp(II, 0, DemandedPtrs, UndefElts2);
- simplifyAndSetOp(II, 3, DemandedPassThrough, UndefElts3);
+ simplifyAndSetOp(II, 0, DemandedPtrs, PoisonElts2);
+ simplifyAndSetOp(II, 3, DemandedPassThrough, PoisonElts3);
// Output elements are undefined if the element from both sources are.
// TODO: can strengthen via mask as well.
- UndefElts = UndefElts2 & UndefElts3;
+ PoisonElts = PoisonElts2 & PoisonElts3;
break;
}
default: {
// Handle target specific intrinsics
std::optional<Value *> V = targetSimplifyDemandedVectorEltsIntrinsic(
- *II, DemandedElts, UndefElts, UndefElts2, UndefElts3,
+ *II, DemandedElts, PoisonElts, PoisonElts2, PoisonElts3,
simplifyAndSetOp);
if (V)
return *V;
@@ -1859,18 +1859,18 @@ Value *InstCombinerImpl::SimplifyDemandedVectorElts(Value *V,
return ShufBO;
}
- simplifyAndSetOp(I, 0, DemandedElts, UndefElts);
- simplifyAndSetOp(I, 1, DemandedElts, UndefElts2);
+ simplifyAndSetOp(I, 0, DemandedElts, PoisonElts);
+ simplifyAndSetOp(I, 1, DemandedElts, PoisonElts2);
// Output elements are undefined if both are undefined. Consider things
// like undef & 0. The result is known zero, not undef.
- UndefElts &= UndefElts2;
+ PoisonElts &= PoisonElts2;
}
- // If we've proven all of the lanes undef, return an undef value.
+ // If we've proven all of the lanes poison, return a poison value.
// TODO: Intersect w/demanded lanes
- if (UndefElts.isAllOnes())
- return UndefValue::get(I->getType());
+ if (PoisonElts.isAllOnes())
+ return PoisonValue::get(I->getType());
return MadeChange ? I : nullptr;
}