Skip to content

Commit 1a282c6

Browse files
author
git apple-llvm automerger
committed
Merge commit '78270cb81bde' from llvm.org/main into next
2 parents b81880b + 78270cb commit 1a282c6

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
@@ -7289,31 +7289,35 @@ static bool isGuaranteedNotToBeUndefOrPoison(
72897289
// BB1:
72907290
// CtxI ; V cannot be undef or poison here
72917291
auto *Dominator = DNode->getIDom();
7292-
while (Dominator) {
7293-
auto *TI = Dominator->getBlock()->getTerminator();
7294-
7295-
Value *Cond = nullptr;
7296-
if (auto BI = dyn_cast_or_null<BranchInst>(TI)) {
7297-
if (BI->isConditional())
7298-
Cond = BI->getCondition();
7299-
} else if (auto SI = dyn_cast_or_null<SwitchInst>(TI)) {
7300-
Cond = SI->getCondition();
7301-
}
7292+
// This check is purely for compile time reasons: we can skip the IDom walk
7293+
// if what we are checking for includes undef and the value is not an integer.
7294+
if (!includesUndef(Kind) || V->getType()->isIntegerTy())
7295+
while (Dominator) {
7296+
auto *TI = Dominator->getBlock()->getTerminator();
7297+
7298+
Value *Cond = nullptr;
7299+
if (auto BI = dyn_cast_or_null<BranchInst>(TI)) {
7300+
if (BI->isConditional())
7301+
Cond = BI->getCondition();
7302+
} else if (auto SI = dyn_cast_or_null<SwitchInst>(TI)) {
7303+
Cond = SI->getCondition();
7304+
}
73027305

7303-
if (Cond) {
7304-
if (Cond == V)
7305-
return true;
7306-
else if (!includesUndef(Kind) && isa<Operator>(Cond)) {
7307-
// For poison, we can analyze further
7308-
auto *Opr = cast<Operator>(Cond);
7309-
if (any_of(Opr->operands(),
7310-
[V](const Use &U) { return V == U && propagatesPoison(U); }))
7306+
if (Cond) {
7307+
if (Cond == V)
73117308
return true;
7309+
else if (!includesUndef(Kind) && isa<Operator>(Cond)) {
7310+
// For poison, we can analyze further
7311+
auto *Opr = cast<Operator>(Cond);
7312+
if (any_of(Opr->operands(), [V](const Use &U) {
7313+
return V == U && propagatesPoison(U);
7314+
}))
7315+
return true;
7316+
}
73127317
}
7313-
}
73147318

7315-
Dominator = Dominator->getIDom();
7316-
}
7319+
Dominator = Dominator->getIDom();
7320+
}
73177321

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

0 commit comments

Comments
 (0)