[LoopFlatten] Fix invalid assertion (PR49571)

The `InductionPHI` is not necessarily the increment instruction, as
demonstrated in pr49571.ll.
This patch removes the assertion and instead bails out from the
`LoopFlatten` pass if that happens.

This fixes https://bugs.llvm.org/show_bug.cgi?id=49571

Reviewed By: SjoerdMeijer

Differential Revision: https://reviews.llvm.org/D99252
This commit is contained in:
Ta-Wei Tu
2021-03-24 18:07:34 +08:00
parent 8fde25b3c3
commit 4c1f74a76c
2 changed files with 29 additions and 2 deletions

View File

@@ -176,8 +176,11 @@ static bool findLoopComponents(
LLVM_DEBUG(dbgs() << "Found limit: "; Limit->dump());
assert(InductionPHI->getNumIncomingValues() == 2);
assert(InductionPHI->getIncomingValueForBlock(Latch) == Increment &&
"PHI value is not increment inst");
if (InductionPHI->getIncomingValueForBlock(Latch) != Increment) {
LLVM_DEBUG(dbgs() << "PHI value is not increment inst");
return false;
}
auto *CI = dyn_cast<ConstantInt>(
InductionPHI->getIncomingValueForBlock(L->getLoopPreheader()));

View File

@@ -0,0 +1,24 @@
; RUN: opt < %s -S -loop-flatten -verify-loop-info -verify-dom-info -verify-scev -verify | FileCheck %s
; CHECK-LABEL: @main
define dso_local void @main() {
entry:
br label %for.cond
for.cond: ; preds = %for.end, %entry
br label %for.body
for.body: ; preds = %for.inc, %for.cond
%a.03 = phi i32 [ 0, %for.cond ], [ %inc, %for.inc ]
br label %for.inc
for.inc: ; preds = %for.body
%0 = add i32 %a.03, 1
%cmp = icmp slt i32 %0, 10
%inc = add nsw i32 %a.03, 1
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.inc
br label %for.cond
}