Skip to content

Commit 086d8e6

Browse files
fhahntru
authored andcommitted
[MachineLICM] Don't allow hoisting invariant loads across mem barrier. (#116987)
The improvements in 63917e1 / #70796 do not check for memory barriers/unmodelled sideeffects, which means we may incorrectly hoist loads across memory barriers. Fix this by checking any machine instruction in the loop is a load-fold barrier. PR: #116987 (cherry picked from commit ef102b4)
1 parent 32cbe24 commit 086d8e6

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

llvm/lib/CodeGen/MachineLICM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1474,7 +1474,7 @@ void MachineLICMBase::InitializeLoadsHoistableLoops() {
14741474
if (!AllowedToHoistLoads[Loop])
14751475
continue;
14761476
for (auto &MI : *MBB) {
1477-
if (!MI.mayStore() && !MI.isCall() &&
1477+
if (!MI.isLoadFoldBarrier() && !MI.mayStore() && !MI.isCall() &&
14781478
!(MI.mayLoad() && MI.hasOrderedMemoryRef()))
14791479
continue;
14801480
for (MachineLoop *L = Loop; L != nullptr; L = L->getParentLoop())

llvm/test/CodeGen/AArch64/machine-licm-hoist-load.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,16 +499,16 @@ for.exit: ; preds = %for.body
499499

500500
@a = external local_unnamed_addr global i32, align 4
501501

502-
; FIXME: Load hoisted out of the loop across memory barriers.
502+
; Make sure the load is not hoisted out of the loop across memory barriers.
503503
define i32 @load_between_memory_barriers() {
504504
; CHECK-LABEL: load_between_memory_barriers:
505505
; CHECK: // %bb.0:
506506
; CHECK-NEXT: adrp x8, :got:a
507507
; CHECK-NEXT: ldr x8, [x8, :got_lo12:a]
508-
; CHECK-NEXT: ldr w0, [x8]
509508
; CHECK-NEXT: .LBB8_1: // %loop
510509
; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
511510
; CHECK-NEXT: //MEMBARRIER
511+
; CHECK-NEXT: ldr w0, [x8]
512512
; CHECK-NEXT: //MEMBARRIER
513513
; CHECK-NEXT: cbz w0, .LBB8_1
514514
; CHECK-NEXT: // %bb.2: // %exit

llvm/test/CodeGen/Mips/lcb5.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ if.end: ; preds = %if.then, %entry
186186
}
187187

188188
; ci: .ent z3
189-
; ci: bteqz $BB6_3
189+
; ci: bteqz $BB6_2
190190
; ci: .end z3
191191

192192
; Function Attrs: nounwind optsize
@@ -210,7 +210,7 @@ if.end: ; preds = %if.then, %entry
210210

211211
; ci: .ent z4
212212
; ci: btnez $BB7_1 # 16 bit inst
213-
; ci: jal $BB7_3 # branch
213+
; ci: jal $BB7_2 # branch
214214
; ci: nop
215215
; ci: $BB7_1:
216216
; ci: .p2align 2

0 commit comments

Comments
 (0)