-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[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
[Constant] Make Constant::getSplatValue return poison on poison #141870
Conversation
This is a follow up from llvm#141845. I'm not sure if this actually NFC but it doesn't seem to affect any of the in-tree tests. I went through the users of getSplatValue to see if anything could be cleaned up but nothing immediately stuck out.
@llvm/pr-subscribers-llvm-analysis Author: Luke Lau (lukel97) ChangesThis is a follow up from #141845. I'm not sure if this actually NFC but it doesn't seem to affect any of the in-tree tests. I went through the users of getSplatValue to see if anything could be cleaned up but nothing immediately stuck out. Full diff: https://github.com/llvm/llvm-project/pull/141870.diff 2 Files Affected:
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/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))
|
@llvm/pr-subscribers-llvm-ir Author: Luke Lau (lukel97) ChangesThis is a follow up from #141845. I'm not sure if this actually NFC but it doesn't seem to affect any of the in-tree tests. I went through the users of getSplatValue to see if anything could be cleaned up but nothing immediately stuck out. Full diff: https://github.com/llvm/llvm-project/pull/141870.diff 2 Files Affected:
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/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))
|
…ing costmodel behaviour This fixes a regression in Analysis/CostModel/RISCV/rvv-load-store.ll where we were now trying to add a cost for materializing a poison in a store: -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store <4 x i32> poison, ptr %p, align 16 +; CHECK-NEXT: Cost Model: Found an estimated cost of 2 for instruction: store <4 x i32> poison, ptr %p, align 16 ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: store <4 x i32> undef, ptr %p, align 16 This came about because it had a check for getSplatValue, which now returns something for poison. So to preserve the existing behaviour, check if the value is undef and return non-constant so no materialization costs are added
) 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.
…#141870) This is a follow up from llvm#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.
…#141870) This is a follow up from llvm#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.
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.