+Philip to get his input too.
I’ve talked with George offline, and here’s a summary:
In D16875, the decision made was: “The LLVM spec is ambiguous about whether we can hoist a non-volatile load above a volatile load when the loads alias. It’s probably best not to exploit this ambiguity at the moment by unconditionally allowing the motion of nonvolatile loads above volatile loads (and vice versa)”
So the testcase: test/Analysis/MemorySSA/volatile-clobber.ll, is checking that a volatile load is the defining access of a load with which it may alias.
Snippet:
; Ensuring that we don’t automatically hoist nonvolatile loads around volatile
; loads
; CHECK-LABEL define void @volatile_only
define void @volatile_only(i32* %arg1, i32* %arg2) {
[…]
; MayAlias
; CHECK: 2 = MemoryDef(1)
; CHECK-NEXT: load volatile i32, i32* %arg1
load volatile i32, i32* %arg1
; CHECK: MemoryUse(2)
; CHECK-NEXT: load i32, i32* %arg2
load i32, i32* %arg2
ret void
}
The testcase: test/Transforms/LICM/volatile-alias.ll checks the opposite, that we do hoist the non-volatile load. This is currently ensured by the AliasSetTracker.
The conclusion I’m drawing is that right now AliasSetTracker and MemorySSA have different behaviors and replacing one with the either will naturally lead to different outcomes.
So, how can I make progress here?
I think it’s reasonable in D40375 to have pointerInvalidatedByLoopWithMSSA only check if the defining access is within the current loop or liveOnEntry, and rely on MemorySSA to either consider a volatile load a clobbering access or not. So, right now the LICM/volatile-alias.ll testcase will behave differently with MemorySSA enabled.
A separate decision, is whether to update getLoadReorderability in MemorySSA to remove the restriction that loads should not alias. That would give the same behavior as the AliasSetTracker.George’s recollection is that the reason MemorySSA didn’t reorder aggressively is because it was untested at the time. Now that MemorySSA is used more widely, it may be a good time to revisit the initial decision?
Thoughts?
Thanks,
Alina