This is an archive of the discontinued LLVM Phabricator instance.

[Scalarizer] No need to gather a scattered extracted element
ClosedPublic

Authored by serge-sans-paille on May 19 2022, 1:23 PM.

Details

Summary

ExtractElement does not produce a vector out of a vector, so there's no need to
call a gather once done.

Fix #54469

Credits to npopov@redhat.com for the original approach.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2022, 1:23 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
serge-sans-paille requested review of this revision.May 19 2022, 1:23 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 19 2022, 1:23 PM
nikic added a comment.May 31 2022, 6:00 AM

There is another patch for this issue in D123684. Haven't looked at either variant yet, but the approach there looks quite different.

nikic added a comment.May 31 2022, 8:59 AM

My current thinking here is that we shouldn't be making this gather() call at all. The code seems to be effectively treating the result of the extractelement as a 1-vector, which doesn't make a lot of sense to me.

I tried the following patch, that just replaces the extractelement with the scattered value: https://gist.github.com/nikic/d09ace51902e03e5b0cf04c528f87c49 Apart from one dead instruction, this seems to be working fine with tests.

What do you think?

llvm/test/Transforms/Scalarizer/global-bug.ll
2

Spurious change :)

serge-sans-paille retitled this revision from [Scalarizer] Support loading from an extracted vector of pointer to [Scalarizer] No need to gather a scattered extracted element.
serge-sans-paille edited the summary of this revision. (Show Details)

Follow @nikic approach there, it's clean and simple. Just fix a little edge case in the finish routine. Note that I could have checked the size of the cleanup vector, but I felt like a more explicit approach would be better.

nikic accepted this revision.Jun 21 2022, 8:09 AM

LGTM

llvm/test/Transforms/Scalarizer/vector-of-pointer-to-vector.ll
6

Maybe add one more test with constant index, as it uses a different code path in the implementation?

This revision is now accepted and ready to land.Jun 21 2022, 8:09 AM
This revision was landed with ongoing or failed builds.Jun 21 2022, 9:46 AM
This revision was automatically updated to reflect the committed changes.