[llvm] 4f93d5c - [BasicBlockUtils] Do not move loop metadata if outer loop header.
Hendrik Greving via llvm-commits
llvm-commits at lists.llvm.org
Mon May 23 16:41:34 PDT 2022
Author: Hendrik Greving
Date: 2022-05-23T16:39:54-07:00
New Revision: 4f93d5cc1d47c6b54a948712b6181dc55d028c88
URL: https://github.com/llvm/llvm-project/commit/4f93d5cc1d47c6b54a948712b6181dc55d028c88
DIFF: https://github.com/llvm/llvm-project/commit/4f93d5cc1d47c6b54a948712b6181dc55d028c88.diff
LOG: [BasicBlockUtils] Do not move loop metadata if outer loop header.
Fixes a bug preventing moving the loop's metadata to an outer loop's header,
which happens if the loop's exit is also the header of an outer loop.
Adjusts test for above.
Fixes #55416.
Differential Revision: https://reviews.llvm.org/D125574
Added:
Modified:
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/test/Transforms/LoopSimplify/update_latch_md2.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index fd92a39d32593..e9983ff821761 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1162,7 +1162,11 @@ SplitBlockPredecessorsImpl(BasicBlock *BB, ArrayRef<BasicBlock *> Preds,
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);
}
}
diff --git a/llvm/test/Transforms/LoopSimplify/update_latch_md2.ll b/llvm/test/Transforms/LoopSimplify/update_latch_md2.ll
index 488860ad190c7..1d54e868890e0 100644
--- a/llvm/test/Transforms/LoopSimplify/update_latch_md2.ll
+++ b/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:
More information about the llvm-commits
mailing list