[llvm] [UndefOrPoison] [CompileTime] Avoid IDom walk unless required. NFC (PR #90092)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 29 09:33:48 PDT 2024
https://github.com/annamthomas updated https://github.com/llvm/llvm-project/pull/90092
>From 2fa9f55ee43e6ac60011ae1b413e9338e0b8d7e4 Mon Sep 17 00:00:00 2001
From: Anna Thomas <anna at azul.com>
Date: Thu, 25 Apr 2024 13:11:41 -0400
Subject: [PATCH] [UndefOrPoison] [CompileTime] Avoid IDom walk unless
required. NFC
If the value is not integer 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 with non-integer values.
---
llvm/lib/Analysis/ValueTracking.cpp | 46 ++++++++++++++++-------------
1 file changed, 25 insertions(+), 21 deletions(-)
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index de38eddaa98fef..087e2daec071cc 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -7283,31 +7283,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;
More information about the llvm-commits
mailing list