Four Possibilities for Load/Store Motion
Load-Load
LW R1, (R2)
LW R3, (R4)
Load-Load can always be interchanged
(if no volatiles)
Load-Store and Store-Store are never interchanged
Store-Load is the only promising program transformation
Load is done earlier than planned, which can only help
Store is done later than planned, which should cause no harm
Two variants of transformation
If load is independent of store, we have load bypassing
If load is dependent on store through memory (e.g., (R1) == (R4)), we have load forwarding
Load-Store
LW R1, (R2)
SW (R3), R4
Store-Store
SW R1, (R2)
SW R3, (R4)
Store-Load
SW (R1), R2
LW R3, (R4)