Skip to content

[Constant] Make Constant::getSplatValue return poison on poison #141870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions llvm/lib/Analysis/ConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3794,11 +3794,6 @@ static Constant *ConstantFoldScalableVectorCall(
SplatOps.push_back(Op);
continue;
}
// TODO: Should getSplatValue return a poison scalar for a poison vector?
if (isa<PoisonValue>(Op)) {
SplatOps.push_back(PoisonValue::get(Op->getType()->getScalarType()));
continue;
}
Constant *Splat = Op->getSplatValue();
if (!Splat)
return nullptr;
Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Analysis/TargetTransformInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,10 @@ TargetTransformInfo::getOperandInfo(const Value *V) {
OperandValueKind OpInfo = OK_AnyValue;
OperandValueProperties OpProps = OP_None;

// undef/poison don't materialize constants.
if (isa<UndefValue>(V))
return {OK_AnyValue, OP_None};

if (isa<ConstantInt>(V) || isa<ConstantFP>(V)) {
if (const auto *CI = dyn_cast<ConstantInt>(V)) {
if (CI->getValue().isPowerOf2())
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/IR/Constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,8 @@ void ConstantVector::destroyConstantImpl() {

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