This is an archive of the discontinued LLVM Phabricator instance.

[EarlyCSE] Allow elimination of redundant writeonly calls
Needs RevisionPublic

Authored by bkramer on Jan 4 2022, 11:11 AM.

Details

Summary

A writeonly call behaves like a readnone call that also contains a store
to a global determined by the call arguments. This means we can remove
duplicated calls if there are no intervening stores.

This only works if MemorySSA is enabled as we use it to check if there
are conflicting memory accesses.

With this change CSE can handle things like "cos(x)+cos(x) => 2*cos(x)"
even with -fmath-errno.

Based on D48388 by Brian Homerding!

Diff Detail

Event Timeline

bkramer created this revision.Jan 4 2022, 11:11 AM
bkramer requested review of this revision.Jan 4 2022, 11:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 4 2022, 11:11 AM
nikic added a comment.Jan 5 2022, 5:28 AM

Can you please pre-commit the test with regenerated check lines?

fhahn added inline comments.Jan 5 2022, 5:28 AM
llvm/test/Transforms/EarlyCSE/memoryssa.ll
160

It might be good to throw in calls with matching and differing arguments?

Drive by: nounwind and nosync come to mind as being somewhat important here. Also willreturn.

reames added a comment.EditedJan 5 2022, 8:31 AM

A couple notes:

  1. writeonly calls can write to their arguments, we should have some test coverage for that case
  1. writeonly calls can still throw and infinite-loop. Since you're removing a following call with the same arguments, we can infer this won't happen, but test coverage and comments needed.

Once tests are added, we can take a closer look at the code.

Edit: I failed to state that the basic idea seems reasonable and worthwhile.

fhahn accepted this revision.Sep 26 2022, 6:11 AM

Marking as changes requested as there are outstanding comments.

This revision is now accepted and ready to land.Sep 26 2022, 6:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 26 2022, 6:11 AM
fhahn requested changes to this revision.Sep 26 2022, 6:11 AM

Actually mark as Request changes

This revision now requires changes to proceed.Sep 26 2022, 6:11 AM