[PATCH] D134279: [MustExec][LICM] Handle latch being part of an inner cycle (PR57780)

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 11 00:32:49 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
nikic marked an inline comment as done.
Closed by commit rG884bb97dca25: [MustExec][LICM] Handle latch being part of an inner cycle (PR57780) (authored by nikic).

Changed prior to commit:
  https://reviews.llvm.org/D134279?vs=462883&id=466715#toc

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134279

Files:
  llvm/lib/Analysis/MustExecute.cpp
  llvm/test/Analysis/MustExecute/pr57780.ll
  llvm/test/Transforms/LICM/pr57780.ll


Index: llvm/test/Transforms/LICM/pr57780.ll
===================================================================
--- llvm/test/Transforms/LICM/pr57780.ll
+++ llvm/test/Transforms/LICM/pr57780.ll
@@ -7,7 +7,6 @@
 define void @test() {
 ; CHECK-LABEL: @test(
 ; CHECK-NEXT:  entry:
-; CHECK-NEXT:    store i16 5, ptr @c, align 2
 ; CHECK-NEXT:    br label [[LOOP:%.*]]
 ; CHECK:       loop:
 ; CHECK-NEXT:    [[V:%.*]] = phi i32 [ 10, [[ENTRY:%.*]] ], [ 0, [[LOOP_LATCH:%.*]] ]
@@ -16,6 +15,7 @@
 ; CHECK:       loop.cont:
 ; CHECK-NEXT:    br i1 false, label [[LOOP_IRREDUCIBLE:%.*]], label [[LOOP_LATCH]]
 ; CHECK:       loop.irreducible:
+; CHECK-NEXT:    store i16 5, ptr @c, align 2
 ; CHECK-NEXT:    br label [[LOOP_LATCH]]
 ; CHECK:       loop.latch:
 ; CHECK-NEXT:    br i1 false, label [[LOOP_IRREDUCIBLE]], label [[LOOP]]
Index: llvm/test/Analysis/MustExecute/pr57780.ll
===================================================================
--- llvm/test/Analysis/MustExecute/pr57780.ll
+++ llvm/test/Analysis/MustExecute/pr57780.ll
@@ -2,9 +2,8 @@
 
 @c = global i16 0, align 2
 
-; FIXME: miscompile
 ; CHECK-LABEL: define void @latch_cycle_irreducible
-; CHECK: store i16 5, ptr @c, align 2 ; (mustexec in: loop)
+; CHECK: store i16 5, ptr @c, align 2{{$}}
 define void @latch_cycle_irreducible() {
 entry:
   br label %loop
@@ -28,9 +27,8 @@
   ret void
 }
 
-; FIXME: miscompile
 ; CHECK-LABEL: define void @latch_cycle_reducible
-; CHECK: store i16 5, ptr @c, align 2 ; (mustexec in: loop)
+; CHECK: store i16 5, ptr @c, align 2{{$}}
 define void @latch_cycle_reducible() {
 entry:
   br label %loop
Index: llvm/lib/Analysis/MustExecute.cpp
===================================================================
--- llvm/lib/Analysis/MustExecute.cpp
+++ llvm/lib/Analysis/MustExecute.cpp
@@ -201,6 +201,15 @@
   SmallPtrSet<const BasicBlock *, 4> Predecessors;
   collectTransitivePredecessors(CurLoop, BB, Predecessors);
 
+  // Bail out if a latch block is part of the predecessor set. In this case
+  // we may take the backedge to the header and not execute other latch
+  // successors.
+  for (const BasicBlock *Pred : predecessors(CurLoop->getHeader()))
+    // Predecessors only contains loop blocks, so we don't have to worry about
+    // preheader predecessors here.
+    if (Predecessors.contains(Pred))
+      return false;
+
   // Make sure that all successors of, all predecessors of BB which are not
   // dominated by BB, are either:
   // 1) BB,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134279.466715.patch
Type: text/x-patch
Size: 2472 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221011/28afc3ba/attachment.bin>


More information about the llvm-commits mailing list