llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[LoopLoadElim] Miscompile: incorrect store-to-load forwarding across mixed-width clobbers

Open ChrisLee02 opened this issue 2 months ago • 1 comments

LoopLoadElimination can incorrectly forward a same-width store value across a mixed-width store that partially clobbers the forwarded value.

This was initially exposed by @nikic in #221531. The LAA change in that PR allows a zero-distance mixed-width dependence to be classified as Forward, which exposes the LLE miscompile: https://llvm.godbolt.org/z/nv6s558jT

While investigating that case, I found that the issue is more general and already reproduces on current trunk without the zero-distance LAA change: https://llvm.godbolt.org/z/qj8P5KzcM

LLE currently discards a non-bitcastable Store-to-Load dependence with continue, but does not treat that store as a clobber of another forwarding candidate for the same load. As a result, it can forward a full-width store value even though a mixed-width store has modified part of that value before the next iteration's load.

ChrisLee02 avatar Sep 19 '26 12:09 ChrisLee02

Hi @nikic, do you have guidance on the intended fix direction here? Marking every non-bitcastable Store-to-Load dependence as a forwarding blocker is too conservative when the partial clobber is overwritten by a later full-width store.

ChrisLee02 avatar Sep 19 '26 12:09 ChrisLee02