This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] Perform memset -> load forwarding
ClosedPublic

Authored by nikic on Nov 3 2022, 3:06 AM.

Details

Summary

InstCombine does some basic store to load forwarding. One case it currently misses is the case where the store is actually a memset. This patch adds support for this case. This is a minimal implementation that only handles a load at the memset base address, without an offset.

GVN is already capable of performing this optimization. Having it in InstCombine can help with phase ordering issues, similar to the existing store to load forwarding.

Diff Detail

Event Timeline

nikic created this revision.Nov 3 2022, 3:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2022, 3:06 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
nikic requested review of this revision.Nov 3 2022, 3:06 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 3 2022, 3:06 AM
spatel added inline comments.Nov 3 2022, 7:15 AM
llvm/test/Transforms/InstCombine/load-store-forward.ll
282–283

Do we have a negative test like this except we're 1-bit short of covering the loaded amount?
Similarly, add a negative test where there's a store or some other interference between the memset and the load?

nikic updated this revision to Diff 472931.Nov 3 2022, 7:29 AM

Add another test

nikic marked an inline comment as done.Nov 3 2022, 7:30 AM
nikic added inline comments.
llvm/test/Transforms/InstCombine/load-store-forward.ll
282–283

Do we have a negative test like this except we're 1-bit short of covering the loaded amount?

There was load_after_memset_0_too_small, but that's using a significantly larger load. I just added load_after_memset_0_too_small_by_one_bit to have a one bit size mismatch.

Similarly, add a negative test where there's a store or some other interference between the memset and the load?

This is covered by the load_after_memset_0_clobber test.

spatel accepted this revision.Nov 3 2022, 7:47 AM

LGTM

This revision is now accepted and ready to land.Nov 3 2022, 7:47 AM
This revision was landed with ongoing or failed builds.Nov 3 2022, 8:05 AM
This revision was automatically updated to reflect the committed changes.
nikic marked an inline comment as done.