[llvm] 6410658 - [Constant] Make Constant::getSplatValue return poison on poison (#141870)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 29 07:01:31 PDT 2025
Author: Luke Lau
Date: 2025-05-29T15:01:28+01:00
New Revision: 64106581b9d4f68eb4911c402b12b154d77a9eb0
URL: https://github.com/llvm/llvm-project/commit/64106581b9d4f68eb4911c402b12b154d77a9eb0
DIFF: https://github.com/llvm/llvm-project/commit/64106581b9d4f68eb4911c402b12b154d77a9eb0.diff
LOG: [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.
Added:
Modified:
llvm/lib/Analysis/ConstantFolding.cpp
llvm/lib/Analysis/TargetTransformInfo.cpp
llvm/lib/IR/Constants.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 40302fbc8ee52..2476dc58375e5 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -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;
diff --git a/llvm/lib/Analysis/TargetTransformInfo.cpp b/llvm/lib/Analysis/TargetTransformInfo.cpp
index 0f857399660fe..2d053e55bdfa9 100644
--- a/llvm/lib/Analysis/TargetTransformInfo.cpp
+++ b/llvm/lib/Analysis/TargetTransformInfo.cpp
@@ -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())
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index fa453309b34ee..a3c725b2af62a 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -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))
More information about the llvm-commits
mailing list