[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
Mon May 23 13:12:13 PDT 2022
hgreving updated this revision to Diff 431464.
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/update_latch_md2.ll
Index: llvm/test/Transforms/LoopSimplify/update_latch_md2.ll
===================================================================
--- llvm/test/Transforms/LoopSimplify/update_latch_md2.ll
+++ llvm/test/Transforms/LoopSimplify/update_latch_md2.ll
@@ -1,13 +1,11 @@
; Tests loop-simplify does not move the loop metadata, because
; the loopexit block is not the latch of the loop _bb6.
-; FIXME(#55416): The metadata should not move.
-
; RUN: opt < %s -passes=loop-simplify -S | FileCheck %s
; CHECK-LABEL: loop.header.loopexit:
; CHECK: br label %loop.header, !llvm.loop !0
; CHECK-LABEL: loop.latch:
-; CHECK-NOT: br i1 %p, label %loop.latch, label %loop.header.loopexit, !llvm.loop !0
+; CHECK: br i1 %p, label %loop.latch, label %loop.header.loopexit, !llvm.loop !0
define void @func(i1 %p) {
entry:
Index: llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
===================================================================
--- llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1162,7 +1162,11 @@
if (NewLatch != OldLatch) {
MDNode *MD = OldLatch->getTerminator()->getMetadata("llvm.loop");
NewLatch->getTerminator()->setMetadata("llvm.loop", MD);
- OldLatch->getTerminator()->setMetadata("llvm.loop", nullptr);
+ // It's still possible that OldLatch is the latch of another inner loop,
+ // in which case we do not remove the metadata.
+ Loop *IL = LI->getLoopFor(OldLatch);
+ if (IL && IL->getLoopLatch() != OldLatch)
+ OldLatch->getTerminator()->setMetadata("llvm.loop", nullptr);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125574.431464.patch
Type: text/x-patch
Size: 1608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220523/2d5ce0fe/attachment.bin>
More information about the llvm-commits
mailing list