This is an archive of the discontinued LLVM Phabricator instance.

[EarlyCSE] Understand WriteOnly function calls in EarlyCSE with MSSA
Needs ReviewPublic

Authored by homerdin on Jun 20 2018, 12:24 PM.

Details

Reviewers
hfinkel
Summary

I am working to expand the coverage of the WriteOnly attribute when applied to functions:

This patch enables earlyCSE to handle calls to WriteOnly functions and updates lastStore and CurrentGeneration variables appropriately. canHandle will return true for WriteOnly function calls whether we have MSSA or not, but for non-MSSA they will never be the same generation (isSameMemGeneration()) and will not be CSE'd.

Add write_only_func attribute to Clang: https://reviews.llvm.org/D46313
Mark libm functions write_only_func when we care about errno: https://reviews.llvm.org/D48386
Infer WriteOnly attribute for functions: https://reviews.llvm.org/D48387

This patch allows EarlyCSE to handle WriteOnly function calls when using MSSA. Without MSSA the WriteOnly call instructions will be tracked, but never qualify to be eliminated.

Any feedback would be appreciated!

Diff Detail

Event Timeline

homerdin created this revision.Jun 20 2018, 12:24 PM
xbolva00 added inline comments.
lib/Transforms/Scalar/EarlyCSE.cpp
1037

Avoid two dyn_cast?

auto *CI = dyn_cast...
if (CI && CI->doesNotReadMemory() && ...)

homerdin updated this revision to Diff 157357.Jul 25 2018, 2:17 PM

Avoiding two dyn_cast.

Is this condition clear, or would it be useful to extend the helper functions to something like CI->onlyWritesMemory()?

Yes, a helper function is a good idea.

Makes sense to me. Obviously needs some test.

lib/Transforms/Scalar/EarlyCSE.cpp
1016

Indentation is off (tabs?).

homerdin updated this revision to Diff 164038.Sep 5 2018, 7:43 AM
homerdin marked an inline comment as done.
homerdin retitled this revision from [NFC][EarlyCSE] Understand WriteOnly function calls in EarlyCSE with MSSA to [EarlyCSE] Understand WriteOnly function calls in EarlyCSE with MSSA.
homerdin edited the summary of this revision. (Show Details)

Fixed indentation, added a test and expanded the summary to explain the difference between early-cse and early-cse-memssa.

homerdin marked an inline comment as done.Sep 5 2018, 7:50 AM

@xbolva00
I ended up not adding a helper function after looking at the existing ones because it won't simplify the code. To follow the current pattern for the helper functions:

OnlyReadsMemory() = ReadNone || ReadOnly
so I could add OnlyWritesMemory() = ReadNone || WriteOnly which is the exact same functionality as doesNotReadMemory()
Either way we would still need the !CI->doesNotAccessMemory.

uenoku added a subscriber: uenoku.Dec 29 2019, 12:34 PM