[llvm] 78270cb - [UndefOrPoison] [CompileTime] Avoid IDom walk unless required. NFC (#90092)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 1 07:38:25 PDT 2024
Author: annamthomas
Date: 2024-05-01T10:38:22-04:00
New Revision: 78270cb81bded99bebc6fd8d515bf7cbeff62db4
URL: https://github.com/llvm/llvm-project/commit/78270cb81bded99bebc6fd8d515bf7cbeff62db4
DIFF: https://github.com/llvm/llvm-project/commit/78270cb81bded99bebc6fd8d515bf7cbeff62db4.diff
LOG: [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.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 1b461e7cfd01f0..fed2061aae3a0d 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;
More information about the llvm-commits
mailing list