[PATCH] D125574: [BasicBlockUtils] Do not move loop metadata if outer loop header.
Hendrik Greving via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 13 12:26:54 PDT 2022
hgreving updated this revision to Diff 429327.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125574/new/
https://reviews.llvm.org/D125574
Files:
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/test/Transforms/LoopSimplify/metadata.ll
Index: llvm/test/Transforms/LoopSimplify/metadata.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/LoopSimplify/metadata.ll
@@ -0,0 +1,34 @@
+; Tests loop-simplify does not move the loop metadata, because
+; the loopexit block is not the latch of the loop _bb6.
+
+; RUN: opt < %s -loop-simplify -S | FileCheck %s
+; CHECK-LABEL: _bb7.loopexit:
+; CHECK-NOT: br label %_bb7, !llvm.loop !0
+; CHECK-LABEL: _bb6:
+; CHECK: br i1 %p, label %_bb6, label %_bb7.loopexit, !llvm.loop !0
+
+define void @func(i1 %p) {
+_bb1:
+ br label %_bb7
+
+_bb7:
+ br i1 %p, label %_bb4, label %_bb2
+
+_bb4:
+ br i1 %p, label %_bb5, label %_bb3
+
+_bb5:
+ br label %_bb3
+
+_bb3:
+ br label %_bb6
+
+_bb6:
+ br i1 %p, label %_bb6, label %_bb7, !llvm.loop !0
+
+_bb2:
+ ret void
+}
+
+!0 = distinct !{!0, !1}
+!1 = !{!"llvm.loop.mustprogress"}
Index: llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1157,7 +1157,7 @@
UpdatePHINodes(BB, NewBB, Preds, BI, HasLoopExit);
}
- if (OldLatch) {
+ if (OldLatch && L == LI->getLoopFor(OldLatch)) {
BasicBlock *NewLatch = L->getLoopLatch();
if (NewLatch != OldLatch) {
MDNode *MD = OldLatch->getTerminator()->getMetadata("llvm.loop");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125574.429327.patch
Type: text/x-patch
Size: 1422 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220513/5a237b21/attachment.bin>
More information about the llvm-commits
mailing list