@@ -7289,31 +7289,35 @@ static bool isGuaranteedNotToBeUndefOrPoison(
7289
7289
// BB1:
7290
7290
// CtxI ; V cannot be undef or poison here
7291
7291
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
+ }
7302
7305
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)
7311
7308
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
+ }
7312
7317
}
7313
- }
7314
7318
7315
- Dominator = Dominator->getIDom ();
7316
- }
7319
+ Dominator = Dominator->getIDom ();
7320
+ }
7317
7321
7318
7322
if (getKnowledgeValidInContext (V, {Attribute::NoUndef}, CtxI, DT, AC))
7319
7323
return true ;
0 commit comments