Skip to content

Commit 6410658

Browse files
authored
[Constant] Make Constant::getSplatValue return poison on poison (#141870)
This is a follow up from #141845. TargetTransformInfo::getOperandInfo needs to be updated to check for undef values as otherwise a splat is considered a constant, and some RISC-V cost model tests will start adding a cost to materialize the constant.
1 parent a5d97eb commit 6410658

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3794,11 +3794,6 @@ static Constant *ConstantFoldScalableVectorCall(
37943794
SplatOps.push_back(Op);
37953795
continue;
37963796
}
3797-
// TODO: Should getSplatValue return a poison scalar for a poison vector?
3798-
if (isa<PoisonValue>(Op)) {
3799-
SplatOps.push_back(PoisonValue::get(Op->getType()->getScalarType()));
3800-
continue;
3801-
}
38023797
Constant *Splat = Op->getSplatValue();
38033798
if (!Splat)
38043799
return nullptr;

llvm/lib/Analysis/TargetTransformInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,10 @@ TargetTransformInfo::getOperandInfo(const Value *V) {
886886
OperandValueKind OpInfo = OK_AnyValue;
887887
OperandValueProperties OpProps = OP_None;
888888

889+
// undef/poison don't materialize constants.
890+
if (isa<UndefValue>(V))
891+
return {OK_AnyValue, OP_None};
892+
889893
if (isa<ConstantInt>(V) || isa<ConstantFP>(V)) {
890894
if (const auto *CI = dyn_cast<ConstantInt>(V)) {
891895
if (CI->getValue().isPowerOf2())

llvm/lib/IR/Constants.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,6 +1711,8 @@ void ConstantVector::destroyConstantImpl() {
17111711

17121712
Constant *Constant::getSplatValue(bool AllowPoison) const {
17131713
assert(this->getType()->isVectorTy() && "Only valid for vectors!");
1714+
if (isa<PoisonValue>(this))
1715+
return PoisonValue::get(cast<VectorType>(getType())->getElementType());
17141716
if (isa<ConstantAggregateZero>(this))
17151717
return getNullValue(cast<VectorType>(getType())->getElementType());
17161718
if (auto *CI = dyn_cast<ConstantInt>(this))

0 commit comments

Comments
 (0)