aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorannamthomas <anna@azul.com>2024-05-01 10:38:22 -0400
committerGitHub <noreply@github.com>2024-05-01 10:38:22 -0400
commit78270cb81bded99bebc6fd8d515bf7cbeff62db4 (patch)
tree3cce72584a89876d1a12c483c870c7cddd1e994c /llvm/lib/Analysis/ValueTracking.cpp
parentf050660f4a60415cd840f7fba7ac3698c38376d0 (diff)
downloadllvm-78270cb81bded99bebc6fd8d515bf7cbeff62db4.zip
llvm-78270cb81bded99bebc6fd8d515bf7cbeff62db4.tar.gz
llvm-78270cb81bded99bebc6fd8d515bf7cbeff62db4.tar.bz2
[UndefOrPoison] [CompileTime] Avoid IDom walk unless required. NFC (#90092)
If the value is not boolean and we are checking for `Undef` or `UndefOrPoison`, we can avoid the potentially expensive IDom walk. This should improve compile time for isGuaranteedNotToBeUndefOrPoison and isGuaranteedNotToBeUndef.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp46
1 files changed, 25 insertions, 21 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 1b461e7..fed2061 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -7289,31 +7289,35 @@ static bool isGuaranteedNotToBeUndefOrPoison(
// BB1:
// CtxI ; V cannot be undef or poison here
auto *Dominator = DNode->getIDom();
- while (Dominator) {
- auto *TI = Dominator->getBlock()->getTerminator();
-
- Value *Cond = nullptr;
- if (auto BI = dyn_cast_or_null<BranchInst>(TI)) {
- if (BI->isConditional())
- Cond = BI->getCondition();
- } else if (auto SI = dyn_cast_or_null<SwitchInst>(TI)) {
- Cond = SI->getCondition();
- }
+ // This check is purely for compile time reasons: we can skip the IDom walk
+ // if what we are checking for includes undef and the value is not an integer.
+ if (!includesUndef(Kind) || V->getType()->isIntegerTy())
+ while (Dominator) {
+ auto *TI = Dominator->getBlock()->getTerminator();
+
+ Value *Cond = nullptr;
+ if (auto BI = dyn_cast_or_null<BranchInst>(TI)) {
+ if (BI->isConditional())
+ Cond = BI->getCondition();
+ } else if (auto SI = dyn_cast_or_null<SwitchInst>(TI)) {
+ Cond = SI->getCondition();
+ }
- if (Cond) {
- if (Cond == V)
- return true;
- else if (!includesUndef(Kind) && isa<Operator>(Cond)) {
- // For poison, we can analyze further
- auto *Opr = cast<Operator>(Cond);
- if (any_of(Opr->operands(),
- [V](const Use &U) { return V == U && propagatesPoison(U); }))
+ if (Cond) {
+ if (Cond == V)
return true;
+ else if (!includesUndef(Kind) && isa<Operator>(Cond)) {
+ // For poison, we can analyze further
+ auto *Opr = cast<Operator>(Cond);
+ if (any_of(Opr->operands(), [V](const Use &U) {
+ return V == U && propagatesPoison(U);
+ }))
+ return true;
+ }
}
- }
- Dominator = Dominator->getIDom();
- }
+ Dominator = Dominator->getIDom();
+ }
if (getKnowledgeValidInContext(V, {Attribute::NoUndef}, CtxI, DT, AC))
return true;