[PATCH] D99252: [LoopFlatten] Fix invalid assertion (PR49571)

Ta-Wei Tu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 24 03:08:51 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4c1f74a76ce8: [LoopFlatten] Fix invalid assertion (PR49571) (authored by TaWeiTu).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D99252/new/

https://reviews.llvm.org/D99252

Files:
  llvm/lib/Transforms/Scalar/LoopFlatten.cpp
  llvm/test/Transforms/LoopFlatten/pr49571.ll


Index: llvm/test/Transforms/LoopFlatten/pr49571.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopFlatten/pr49571.ll
@@ -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
+}
Index: llvm/lib/Transforms/Scalar/LoopFlatten.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopFlatten.cpp
+++ llvm/lib/Transforms/Scalar/LoopFlatten.cpp
@@ -176,8 +176,11 @@
   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()));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99252.332917.patch
Type: text/x-patch
Size: 1688 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210324/971c38da/attachment.bin>


More information about the llvm-commits mailing list