This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Add combine for extract_vector_elt(build_vector, cst)
ClosedPublic

Authored by aemerson on Mar 2 2021, 11:55 PM.

Diff Detail

Event Timeline

aemerson created this revision.Mar 2 2021, 11:55 PM
aemerson requested review of this revision.Mar 2 2021, 11:55 PM
arsenm added inline comments.Mar 3 2021, 6:33 AM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3680–3683

What about G_BUILD_VECTOR_TRUNC?

This also probably should check for legality / before legalize. The DAG version also has this hasOneUseCheck:

(VecOp.hasOneUse() || TLI.aggressivelyPreferBuildVectorSources(VecVT))) {
llvm/test/CodeGen/AArch64/GlobalISel/combine-extract-vec-elt.mir
26

Should also have an out of bounds case

aemerson added inline comments.Mar 3 2021, 9:59 AM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3680–3683

What about G_BUILD_VECTOR_TRUNC?

We'd have to insert a scalar truncate, which the dagcombine doesn't seem to do. I can try it though.

aemerson updated this revision to Diff 327865.Mar 3 2021, 11:32 AM

New patch.

With the oneuse check in place, it now doesn't handle one of the cases I was interested in, where we see one extract for each element of the BV. I'll create a new patch to combine that away, probably starting from a build_vector.

paquette added inline comments.Mar 3 2021, 5:27 PM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3678

I would guess this is faster than getConstantVRegValWithLookThrough? Maybe check this first?

3686

I guess this is slightly more concise

3692

Can you use the getTargetLowering() helper function here?

3695

Would it be better to make a LLT variant of this function?

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
645

Why no test for this?

aemerson added inline comments.Mar 4 2021, 9:32 AM
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp
3695

I'm not sure that's the right idea. Having 2 sets of hooks for everything sounds like a road we want to avoid as much as possible.

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
645

Because it doesn't actually do anything. There's no lowering functionality implemented, but in order to test the combine we need something here that makes it seem like we have legalization support. So far I haven't seen this TRUNC variant generated in real code.

aemerson updated this revision to Diff 328215.Mar 4 2021, 9:43 AM

Address comments.

aemerson updated this revision to Diff 328248.Mar 4 2021, 11:10 AM

Fix AMDGPU test crashes due to not specifying enough types to legality query. I had to undo some of the changes in the last patch to do this.

paquette accepted this revision.Mar 8 2021, 2:28 PM

This LGTM at this point?

This revision is now accepted and ready to land.Mar 8 2021, 2:28 PM