-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[UndefOrPoison] [CompileTime] Avoid IDom walk unless required. NFC #90092
Conversation
@llvm/pr-subscribers-llvm-analysis Author: None (annamthomas) ChangesWhen we are only checking for UndefKind and if the value we're checking for is not a boolean, we can avoid the potentially expensive IDom walk. isGuaranteedNotToBeUndef() is used in CVP and LVI. Full diff: https://github.com/llvm/llvm-project/pull/90092.diff 1 Files Affected:
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index de38eddaa98fef..95968368a7d719 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 do not need to do the
+ // IDom walk if we are checking for only undef and the value is not a boolean.
+ if (includesPoison(Kind) || V->getType()->isIntOrIntVectorTy(1))
+ 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;
|
261dd39
to
f0adf7f
Compare
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.
f0adf7f
to
2fa9f55
Compare
ping @nikic? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…lvm#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.
If the value is not boolean and we are checking for
Undef
orUndefOrPoison
, we can avoid the potentially expensive IDom walk.This should improve compile time for isGuaranteedNotToBeUndefOrPoison
and isGuaranteedNotToBeUndef.