[ValueTracking] Replace dyn_cast with dyn_cast_or_null to account for getTerminator...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 8 Feb 2022 13:29:49 +0000 (13:29 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 8 Feb 2022 13:33:26 +0000 (13:33 +0000)
Noticed while running checks on D117995 - a hexagon regression test was managing to return a block without a terminator

llvm/lib/Analysis/ValueTracking.cpp

index c14bdb8..a93430c 100644 (file)
@@ -5125,10 +5125,10 @@ static bool isGuaranteedNotToBeUndefOrPoison(const Value *V,
     auto *TI = Dominator->getBlock()->getTerminator();
 
     Value *Cond = nullptr;
-    if (auto BI = dyn_cast<BranchInst>(TI)) {
+    if (auto BI = dyn_cast_or_null<BranchInst>(TI)) {
       if (BI->isConditional())
         Cond = BI->getCondition();
-    } else if (auto SI = dyn_cast<SwitchInst>(TI)) {
+    } else if (auto SI = dyn_cast_or_null<SwitchInst>(TI)) {
       Cond = SI->getCondition();
     }