aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Constants.cpp
diff options
context:
space:
mode:
authorJuneyoung Lee <aqjune@gmail.com>2021-01-05 10:09:49 +0900
committerJuneyoung Lee <aqjune@gmail.com>2021-01-06 12:10:33 +0900
commit29f8628d1fc8d96670e13562c4d92fc916bd0ce1 (patch)
tree1da50486f952374694247a04233515a2ff98c1e8 /llvm/lib/IR/Constants.cpp
parent8444a2494d3d58baae373e66f8a7070e03c62cc2 (diff)
downloadllvm-29f8628d1fc8d96670e13562c4d92fc916bd0ce1.zip
llvm-29f8628d1fc8d96670e13562c4d92fc916bd0ce1.tar.gz
llvm-29f8628d1fc8d96670e13562c4d92fc916bd0ce1.tar.bz2
[Constant] Add containsPoisonElement
This patch - Adds containsPoisonElement that checks existence of poison in constant vector elements, - Renames containsUndefElement to containsUndefOrPoisonElement to clarify its behavior & updates its uses properly With this patch, isGuaranteedNotToBeUndefOrPoison's tests w.r.t constant vectors are added because its analysis is improved. Thanks! Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D94053
Diffstat (limited to 'llvm/lib/IR/Constants.cpp')
-rw-r--r--llvm/lib/IR/Constants.cpp25
1 files changed, 18 insertions, 7 deletions
diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp
index a38302d..5aa819d 100644
--- a/llvm/lib/IR/Constants.cpp
+++ b/llvm/lib/IR/Constants.cpp
@@ -304,31 +304,42 @@ bool Constant::isElementWiseEqual(Value *Y) const {
return isa<UndefValue>(CmpEq) || match(CmpEq, m_One());
}
-bool Constant::containsUndefElement() const {
- if (auto *VTy = dyn_cast<VectorType>(getType())) {
- if (isa<UndefValue>(this))
+static bool
+containsUndefinedElement(const Constant *C,
+ function_ref<bool(const Constant *)> HasFn) {
+ if (auto *VTy = dyn_cast<VectorType>(C->getType())) {
+ if (HasFn(C))
return true;
- if (isa<ConstantAggregateZero>(this))
+ if (isa<ConstantAggregateZero>(C))
return false;
- if (isa<ScalableVectorType>(getType()))
+ if (isa<ScalableVectorType>(C->getType()))
return false;
for (unsigned i = 0, e = cast<FixedVectorType>(VTy)->getNumElements();
i != e; ++i)
- if (isa<UndefValue>(getAggregateElement(i)))
+ if (HasFn(C->getAggregateElement(i)))
return true;
}
return false;
}
+bool Constant::containsUndefOrPoisonElement() const {
+ return containsUndefinedElement(
+ this, [&](const auto *C) { return isa<UndefValue>(C); });
+}
+
+bool Constant::containsPoisonElement() const {
+ return containsUndefinedElement(
+ this, [&](const auto *C) { return isa<PoisonValue>(C); });
+}
+
bool Constant::containsConstantExpression() const {
if (auto *VTy = dyn_cast<FixedVectorType>(getType())) {
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i)
if (isa<ConstantExpr>(getAggregateElement(i)))
return true;
}
-
return false;
}