This was found by oss-fuzz. The switch will get canonicalized to a branch, but if it hasn't been when we run LFTR, we crashed on an unneeded assert.
// using it.
if (!DisableLFTR) {
BasicBlock *PreHeader = L->getLoopPreheader();
- BranchInst *PreHeaderBR = cast<BranchInst>(PreHeader->getTerminator());
SmallVector<BasicBlock*, 16> ExitingBlocks;
L->getExitingBlocks(ExitingBlocks);
// Avoid high cost expansions. Note: This heuristic is questionable in
// that our definition of "high cost" is not exactly principled.
if (Rewriter.isHighCostExpansion(ExitCount, L, SCEVCheapExpansionBudget,
- TTI, PreHeaderBR))
+ TTI, PreHeader->getTerminator()))
continue;
// Check preconditions for proper SCEVExpander operation. SCEV does not
declare i32 @llvm.loop.decrement.reg.i32(i32, i32)
+; This used to crash, we're basically just checking that it doesn't.
+define void @switch_preheader() {
+; CHECK-LABEL: @switch_preheader(
+; CHECK-NEXT: switch i32 -1, label [[X:%.*]] [
+; CHECK-NEXT: ]
+; CHECK: x:
+; CHECK-NEXT: br i1 false, label [[X]], label [[BB:%.*]]
+; CHECK: BB:
+; CHECK-NEXT: ret void
+;
+ switch i32 -1, label %x []
+
+x: ; preds = %x, %0
+ br i1 false, label %x, label %BB
+
+BB: ; preds = %x
+ ret void
+}