Skip to content

Commit

Permalink
[MachineLICM] Don't allow hoisting invariant loads across mem barrier. (
Browse files Browse the repository at this point in the history
llvm#116987)

The improvements in 63917e1 / llvm#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: llvm#116987
(cherry picked from commit ef102b4)
  • Loading branch information
fhahn authored and tru committed Nov 25, 2024
1 parent 32cbe24 commit 086d8e6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/MachineLICM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,7 @@ void MachineLICMBase::InitializeLoadsHoistableLoops() {
if (!AllowedToHoistLoads[Loop])
continue;
for (auto &MI : *MBB) {
if (!MI.mayStore() && !MI.isCall() &&
if (!MI.isLoadFoldBarrier() && !MI.mayStore() && !MI.isCall() &&
!(MI.mayLoad() && MI.hasOrderedMemoryRef()))
continue;
for (MachineLoop *L = Loop; L != nullptr; L = L->getParentLoop())
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/AArch64/machine-licm-hoist-load.ll
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,16 @@ for.exit: ; preds = %for.body

@a = external local_unnamed_addr global i32, align 4

; FIXME: Load hoisted out of the loop across memory barriers.
; Make sure the load is not hoisted out of the loop across memory barriers.
define i32 @load_between_memory_barriers() {
; CHECK-LABEL: load_between_memory_barriers:
; CHECK: // %bb.0:
; CHECK-NEXT: adrp x8, :got:a
; CHECK-NEXT: ldr x8, [x8, :got_lo12:a]
; CHECK-NEXT: ldr w0, [x8]
; CHECK-NEXT: .LBB8_1: // %loop
; CHECK-NEXT: // =>This Inner Loop Header: Depth=1
; CHECK-NEXT: //MEMBARRIER
; CHECK-NEXT: ldr w0, [x8]
; CHECK-NEXT: //MEMBARRIER
; CHECK-NEXT: cbz w0, .LBB8_1
; CHECK-NEXT: // %bb.2: // %exit
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/Mips/lcb5.ll
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ if.end: ; preds = %if.then, %entry
}

; ci: .ent z3
; ci: bteqz $BB6_3
; ci: bteqz $BB6_2
; ci: .end z3

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

; ci: .ent z4
; ci: btnez $BB7_1 # 16 bit inst
; ci: jal $BB7_3 # branch
; ci: jal $BB7_2 # branch
; ci: nop
; ci: $BB7_1:
; ci: .p2align 2
Expand Down

0 comments on commit 086d8e6

Please sign in to comment.