Clobber refers to an access (or instruction) overwriting some part of the memory that another access (or instruction) is either reading from or writing to.
The terminology for “clobber” is used similar to that of the synonym “thrash”, when saying “the cache is being thrashed”; both refer to overwriting memory.
Let’s use the example from the documentation:
define void @foo() {
entry:
%p1 = alloca i8
%p2 = alloca i8
%p3 = alloca i8
; 1 = MemoryDef(liveOnEntry)
store i8 0, i8* %p3
br label %while.cond
while.cond:
; 6 = MemoryPhi({%0,1},{if.end,4})
br i1 undef, label %if.then, label %if.else
if.then:
; 2 = MemoryDef(6)
store i8 0, i8* %p1
br label %if.end
if.else:
; 3 = MemoryDef(6)
store i8 1, i8* %p2
br label %if.end
if.end:
; 5 = MemoryPhi({if.then,2},{if.else,3})
; MemoryUse(5)
%1 = load i8, i8* %p1
; 4 = MemoryDef(5)
store i8 2, i8* %p2
; MemoryUse(1)
%2 = load i8, i8* %p3
br label %while.cond
}
In MemorySSA when we look for the clobbering access, this translates to “look up the IR and find the next MemoryAccess that can write to the same memory that I am reading from or writing to.”
For the first access: “; 1 = MemoryDef(liveOnEntry)”, its operand is liveOnEntry. So “1”'s clobbering access is “liveOnEntry”. The “liveOnEntry” is just a marker referring to whatever value existed at that memory location.
The access inside the loop: “2 = MemoryDef(6)” says its location may be clobbered by “; 6 = MemoryPhi(…)”. This means that the memory location modified by the store instruction “store i8 0, i8* %p1” may have been modified by an access in the phi’s access list: “; 6 = MemoryPhi({%0,1},{if.end,4})”. This could be either the MemoryDef outside the loop (1), or the MemoryDef inside the loop (4).
The access: “; MemoryUse(5)” is a read only. It’s clobbering access (i.e. the access that writes the memory that’s being read at this point, can be found by looking at access “; 5 = MemoryPhi({if.then,2},{if.else,3})”.
This kind of information helps in program analysis. For example, if the code was updated such that we have “2 = MemoryDef(liveOnEntry)” inside the loop, when looking for the clobbering access we will notice there is no access inside the loop that writes to the same memory location.
I hope this helps.