This is an archive of the discontinued LLVM Phabricator instance.

[LoopVectorizer] Don't pass the instruction pointer from getMemInstScalarizationCost.
ClosedPublic

Authored by jonpa on Sep 24 2018, 6:42 AM.

Details

Summary

I discovered while using D52351 (which fixes so that operands scalarization overhead cost is not added if target keeps addresses in GPRs), that some vector loads now got a zero cost. This was because the scalar load can be folded into e.g. an add as one of the operands. The problem is that the folding of the load can only occur in the scalar version, not if the load is vectorized.

I think the simplest solution is to not pass the instruction pointer to getMemoryOpCost() from getMemInstScalarizationCost. Only if that is passed does the SystemZ implementation consider the folding of the load into the user.

Diff Detail

Event Timeline

jonpa created this revision.Sep 24 2018, 6:42 AM
jonpa updated this revision to Diff 167263.Sep 27 2018, 3:28 AM

It seems like a simpler solution to simply not pass the instruction pointer when making this query for a scalarized memory instruction, if VF > 1. This is equivalent, and it doesn't appear to break any tests. Theoretically, there may be use for the instruction pointer, but it seems like there isn't one at the moment.

I can imagine in the SystemZ case that if the user is also scalarized, then the scalarized load is actually folded also in the vectorized loop. I suspect this may happen for i64 multiply. This is however NFC on SPEC compared to using the 'Scalarized' parameter.

The test has an IV increment of 2, which makes it scalarized. Is this clear enough?

Do you agree this is simpler and better?

jonpa retitled this revision from [TargetTransformInfo] Pass a new argument 'Scalarized' to getMemoryOpCost. to [LoopVectorizer] Don't pass the instruction pointer from getMemInstScalarizationCost..Oct 5 2018, 7:46 AM
jonpa edited the summary of this revision. (Show Details)
jonpa added a comment.Oct 27 2018, 6:26 AM

Since this only affects SystemZ, I suppose no one objects to this then?

uweigand added inline comments.Oct 30 2018, 6:31 AM
lib/Transforms/Vectorize/LoopVectorize.cpp
5262

I think it would be good to add a comment why no instruction pointer is passed. Otherwise this LGTM.

jonpa accepted this revision.Oct 30 2018, 7:40 AM
jonpa marked an inline comment as done.

Added a comment as suggested.
Committed in r345603.

This revision is now accepted and ready to land.Oct 30 2018, 7:40 AM
jonpa closed this revision.Oct 30 2018, 7:41 AM