This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] fold fake vector extract to shift+trunc
ClosedPublic

Authored by spatel on Oct 4 2021, 11:28 AM.

Details

Summary

We already handle more complicated cases like:
extelt (bitcast (inselt poison, X, 0)) --> trunc (lshr X)

But we missed this simpler pattern:
https://alive2.llvm.org/ce/z/D55h64 / https://alive2.llvm.org/ce/z/GKzzRq

This is part of solving:
https://llvm.org/PR52057

I made the transform depend on legal/desirable int type to avoid creating a shift of an illegal type (for example i128). I'm not sure if that restriction is actually necessary, but we can change that as a follow-up if the backend can deal with integer ops on too-wide illegal types.

The pile of AVX512 test changes are all neutral AFAICT - the x86 backend seems to know how to turn that into the expected "kmov" instructions.

Diff Detail

Event Timeline

spatel created this revision.Oct 4 2021, 11:28 AM
spatel requested review of this revision.Oct 4 2021, 11:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 4 2021, 11:28 AM
dmgreen added inline comments.Oct 5 2021, 12:49 AM
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
204

Does this need to check for scalable vectors nowadays?

spatel added inline comments.Oct 5 2021, 5:07 AM
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
204

The source type must be a scalar integer, so we can't have a scalable vector in this code block, right?
If that's correct, I can add an assert that we have a FixedVectorType.

spatel updated this revision to Diff 377286.Oct 5 2021, 9:56 AM

Patch updated:
Added an assert for FixedVectorType.

spatel marked an inline comment as done.Oct 5 2021, 9:56 AM
dmgreen added inline comments.Oct 5 2021, 1:04 PM
llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
204

Ah, because it's from a bitcast. Sounds good then.

lebedev.ri edited the summary of this revision. (Show Details)Oct 5 2021, 1:15 PM
lebedev.ri accepted this revision.Oct 5 2021, 1:17 PM

LG, thank you.

This revision is now accepted and ready to land.Oct 5 2021, 1:17 PM
This revision was automatically updated to reflect the committed changes.