aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Constants.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2024-04-18 15:44:12 +0900
committerGitHub <noreply@github.com>2024-04-18 15:44:12 +0900
commit1baa3850656382d1d549a13f8a716ef5dc886eb8 (patch)
tree9aa3086c00912cecf5489b14ef4bbba04390a625 /llvm/lib/IR/Constants.cpp
parent7ec342ba16ca97206aa2ddd5b7ec0da063042e03 (diff)
downloadllvm-1baa3850656382d1d549a13f8a716ef5dc886eb8.zip
llvm-1baa3850656382d1d549a13f8a716ef5dc886eb8.tar.gz
llvm-1baa3850656382d1d549a13f8a716ef5dc886eb8.tar.bz2
[IR][PatternMatch] Only accept poison in getSplatValue() (#89159)
In #88217 a large set of matchers was changed to only accept poison values in splats, but not undef values. This is because we now use poison for non-demanded vector elements, and allowing undef can cause correctness issues. This patch covers the remaining matchers by changing the AllowUndef parameter of getSplatValue() to AllowPoison instead. We also carry out corresponding renames in matchers. As a followup, we may want to change the default for things like m_APInt to m_APIntAllowPoison (as this is much less risky when only allowing poison), but this change doesn't do that. There is one caveat here: We have a single place (X86FixupVectorConstants) which does require handling of vector splats with undefs. This is because this works on backend constant pool entries, which currently still use undef instead of poison for non-demanded elements (because SDAG as a whole does not have an explicit poison representation). As it's just the single use, I've open-coded a getSplatValueAllowUndef() helper there, to discourage use in any other places.
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r--llvm/lib/IR/Constants.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index 45b359a..5268ecc 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -1696,14 +1696,14 @@ void ConstantVector::destroyConstantImpl() {
getType()->getContext().pImpl->VectorConstants.remove(this);
}
-Constant *Constant::getSplatValue(bool AllowUndefs) const {
+Constant *Constant::getSplatValue(bool AllowPoison) const {
assert(this->getType()->isVectorTy() && "Only valid for vectors!");
if (isa<ConstantAggregateZero>(this))
return getNullValue(cast<VectorType>(getType())->getElementType());
if (const ConstantDataVector *CV = dyn_cast<ConstantDataVector>(this))
return CV->getSplatValue();
if (const ConstantVector *CV = dyn_cast<ConstantVector>(this))
- return CV->getSplatValue(AllowUndefs);
+ return CV->getSplatValue(AllowPoison);
// Check if this is a constant expression splat of the form returned by
// ConstantVector::getSplat()
@@ -1728,7 +1728,7 @@ Constant *Constant::getSplatValue(bool AllowUndefs) const {
return nullptr;
}
-Constant *ConstantVector::getSplatValue(bool AllowUndefs) const {
+Constant *ConstantVector::getSplatValue(bool AllowPoison) const {
// Check out first element.
Constant *Elt = getOperand(0);
// Then make sure all remaining elements point to the same value.
@@ -1738,15 +1738,15 @@ Constant *ConstantVector::getSplatValue(bool AllowUndefs) const {
continue;
// Strict mode: any mismatch is not a splat.
- if (!AllowUndefs)
+ if (!AllowPoison)
return nullptr;
- // Allow undefs mode: ignore undefined elements.
- if (isa<UndefValue>(OpC))
+ // Allow poison mode: ignore poison elements.
+ if (isa<PoisonValue>(OpC))
continue;
// If we do not have a defined element yet, use the current operand.
- if (isa<UndefValue>(Elt))
+ if (isa<PoisonValue>(Elt))
Elt = OpC;
if (OpC != Elt)