Skip to content

Commit 2fa9f55

Browse files
committed
[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.
1 parent d94aeb5 commit 2fa9f55

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7283,31 +7283,35 @@ static bool isGuaranteedNotToBeUndefOrPoison(
72837283
// BB1:
72847284
// CtxI ; V cannot be undef or poison here
72857285
auto *Dominator = DNode->getIDom();
7286-
while (Dominator) {
7287-
auto *TI = Dominator->getBlock()->getTerminator();
7288-
7289-
Value *Cond = nullptr;
7290-
if (auto BI = dyn_cast_or_null<BranchInst>(TI)) {
7291-
if (BI->isConditional())
7292-
Cond = BI->getCondition();
7293-
} else if (auto SI = dyn_cast_or_null<SwitchInst>(TI)) {
7294-
Cond = SI->getCondition();
7295-
}
7286+
// This check is purely for compile time reasons: we can skip the IDom walk
7287+
// if what we are checking for includes undef and the value is not an integer.
7288+
if (!includesUndef(Kind) || V->getType()->isIntegerTy())
7289+
while (Dominator) {
7290+
auto *TI = Dominator->getBlock()->getTerminator();
7291+
7292+
Value *Cond = nullptr;
7293+
if (auto BI = dyn_cast_or_null<BranchInst>(TI)) {
7294+
if (BI->isConditional())
7295+
Cond = BI->getCondition();
7296+
} else if (auto SI = dyn_cast_or_null<SwitchInst>(TI)) {
7297+
Cond = SI->getCondition();
7298+
}
72967299

7297-
if (Cond) {
7298-
if (Cond == V)
7299-
return true;
7300-
else if (!includesUndef(Kind) && isa<Operator>(Cond)) {
7301-
// For poison, we can analyze further
7302-
auto *Opr = cast<Operator>(Cond);
7303-
if (any_of(Opr->operands(),
7304-
[V](const Use &U) { return V == U && propagatesPoison(U); }))
7300+
if (Cond) {
7301+
if (Cond == V)
73057302
return true;
7303+
else if (!includesUndef(Kind) && isa<Operator>(Cond)) {
7304+
// For poison, we can analyze further
7305+
auto *Opr = cast<Operator>(Cond);
7306+
if (any_of(Opr->operands(), [V](const Use &U) {
7307+
return V == U && propagatesPoison(U);
7308+
}))
7309+
return true;
7310+
}
73067311
}
7307-
}
73087312

7309-
Dominator = Dominator->getIDom();
7310-
}
7313+
Dominator = Dominator->getIDom();
7314+
}
73117315

73127316
if (getKnowledgeValidInContext(V, {Attribute::NoUndef}, CtxI, DT, AC))
73137317
return true;

0 commit comments

Comments
 (0)