Skip to content

Commit b52dc77

Browse files
committed
[MachineLoopInfo] Fix getLoopID to handle multi latches.
This patch also fixed CodegenPrepare to reserve loop metadata when merging blocks. This fixes issue #102632
1 parent 57c1e21 commit b52dc77

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

llvm/lib/CodeGen/CodeGenPrepare.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,6 +1183,12 @@ void CodeGenPrepare::eliminateMostlyEmptyBlock(BasicBlock *BB) {
11831183
}
11841184
}
11851185

1186+
// Reserve loop Metadata.
1187+
if (BI->hasMetadata(LLVMContext::MD_loop)) {
1188+
for (auto *Pred : predecessors(BB))
1189+
Pred->getTerminator()->copyMetadata(*BI, LLVMContext::MD_loop);
1190+
}
1191+
11861192
// The PHIs are now updated, change everything that refers to BB to use
11871193
// DestBB and remove BB.
11881194
BB->replaceAllUsesWith(DestBB);

llvm/lib/CodeGen/MachineLoopInfo.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,6 @@ MDNode *MachineLoop::getLoopID() const {
211211
break;
212212
}
213213
}
214-
if (!MD)
215-
return nullptr;
216214
if (!LoopID)
217215
LoopID = MD;
218216
else if (MD != LoopID)

llvm/test/CodeGen/X86/code-align-loops.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ for.body5: ; preds = %for.body, %for.body
111111
; }
112112
; }
113113
; CHECK-LABEL: test3_multilatch:
114-
; ALIGN: .p2align 4, 0x90
114+
; ALIGN: .p2align 6, 0x90
115115
; ALIGN-NEXT: .LBB2_1: # %while.cond
116116
define dso_local i32 @test3_multilatch() #0 {
117117
entry:

0 commit comments

Comments
 (0)