[llvm] [UndefOrPoison] [CompileTime] Avoid IDom walk unless required. NFC (PR #90092)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 26 09:51:33 PDT 2024
================
@@ -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 a boolean.
+ if (!includesUndef(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)) {
----------------
annamthomas wrote:
err, yes, thanks :)
Actually, I still this skipping the code entirely (apart from adding the limit to idoms) might be useful for non-integer values (for example: trying to prove noundef for pointer loads across phis, which we do downstream).
I checked how many lit tests in transform directory can skip this code entirely (added an assert if the Value is non-integer when we reach this IDom walk) : ~100 tests and some of them in LoopVectorizer are pointer Values.
https://github.com/llvm/llvm-project/pull/90092
More information about the llvm-commits
mailing list