This is an archive of the discontinued LLVM Phabricator instance.

[MemorySSA] Add OptimizeUses flag
AbandonedPublic

Authored by Prazek on Feb 24 2017, 10:42 AM.

Details

Summary

This will help much in testing updating
of memory accesses with invariant.group in the future.

Event Timeline

Prazek created this revision.Feb 24 2017, 10:42 AM
dberlin edited edge metadata.Feb 24 2017, 10:48 AM

Please, no.
If you need a flag, please make a hidden command line flag.

This should not be user controllable.

Please, no.
If you need a flag, please make a hidden command line flag.

This should not be user controllable.

Is there a way to pass command line flag in unit tests?
I will have to write a couple of tests using invariant.group, and I would like to avoid hacky tricks like in this test, which would make it simpler.

Could you explain the issue with optimizing uses that is making it hard to write tests?
I mean, at worst we could add a protected constructor, but i'd like to understand the underlying issue first.

(because otherwise, you aren't testing the thing that users use :P)

Could you explain the issue with optimizing uses that is making it hard to write tests?
I mean, at worst we could add a protected constructor, but i'd like to understand the underlying issue first.

I would like to make the walker smart enough to optimize invariant.group as good as in OptimizeUses.
If invariant.group attributest will be set before buildin mssa, then it will be optimized by UseOptimizer
The only way to test it right now is either:

  • create loads/stores, setup memory ssa, add invariant.group
  • setup mssa, start adding new stores and loads with invariant.group

Can't you just call setDefiningAccess on the uses in question to set them?

Can't you just call setDefiningAccess on the uses in question to set them?

Not sure what do you mean, so I will describe it with more details with new resaon.

I want to have separate list (or other strusture) having only memory accesses with invariant group.
I would like to make a unit test to check if getClobberingAccess returns the best memory def without help of OptimizeUses.

creating instructions, building mssa, then setting up invariant group attributes, and then calling getClobberingAccess won't work, because the link list for invariant groups will be empty (unless mssa would have method like "addInvariantGroupToMemoryAccess", which we probably don't want to have, because no passes should need it.

other way is to create mssa; create instructions with invariant group; insert each instruction into mssa; then call getClobberingAccess, but this seems to be more painfull, than just:

create instructions with invariant group; create mssa WITHOUT optimizing uses; test getClobberingAccess

Can't you just call setDefiningAccess on the uses in question to set them?

Not sure what do you mean, so I will describe it with more details with new resaon.

i mean if the uses are getting optimized, you can just reset them to their original access.

I want to have separate list (or other strusture) having only memory accesses with invariant group.

I'm not strongly opposed, but it'd have to have a good reason.
This strikes me as invariant.group possibly not being well designed if we have to do this to make it work well in something that actually wants to process them en-masse.
But i'll set that aside.

I would like to make a unit test to check if getClobberingAccess returns the best memory def without help of OptimizeUses.

Okay.

So just call setDefiningAccess on the use and reset it to the nearest store.

creating instructions, building mssa, then setting up invariant group attributes, and then calling getClobberingAccess won't work, because the link list for invariant groups will be empty

The optimal way to test would seem to me to be:
create instructions, add invariant group attributes, build memoryssa, store away,what things optimized, reset defining access on each load to nearest store, call get clobbering access, compare that we got exactly same result as we did before.

THis verifies both ways give the same results.

What am i missing?

other way is to create mssa; create instructions with invariant group; insert each instruction into mssa; then call getClobberingAccess, but this seems to be more painfull, than just:

Why is this more painful?
It's almost certainly <100 lines of code, and even then, can be done trivially with a simpler helper function.

create instructions with invariant group; create mssa WITHOUT optimizing uses; test getClobberingAccess

Except you aren't testing a thing that a user would use here?
You are also basically embedded strong knowledge about MSSA into your test.
What if i added a trivial optimizer during renaming or otherwise change the linking?
Now your test breaks.
Whereas, if you take the "painful" approach, it just always works.
Or if you just set the test up to be the way you want it, using setDefiningAccess, it will also always work.

I would strongly prefer one of these two methods over trying to control, internally, for testing, what memoryssa does, with flags you pass during building it.

Prazek abandoned this revision.Apr 10 2017, 4:57 AM