This is an archive of the discontinued LLVM Phabricator instance.

[LegalizeTypes] Teach PromoteIntRes_BITCAST to better handle a bitcast with vector output type and a vector input type that needs to be widened
ClosedPublic

Authored by craig.topper on Oct 12 2018, 4:43 PM.

Details

Summary

Previously if we had a bitcast vector output type that needs promotion and a vector input type that needs widening we would just do a stack store and load to handle the conversion. We can do a little better if we can widen the bitcast to a legal vector type the same size as the widened input type. Then we can do the bitcast between this widened type and the widened input type. Afterwards we can extract_subvector back to the original output and any_extend that. Type legalization will then circle back and handle promotion of the extract_subvector and the any_extend will just be removed. This will avoid going through the stack and allows us to remove a custom version of this legalization from X86.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Oct 12 2018, 4:43 PM

I'd like to see more test coverage for this, I think. If I'm following correctly, this should affect something like the following on AArch64?

define <2 x i16> @foo(<2 x half> %x) {
  %y = bitcast <2 x half> %x to <2 x i16>
  ret <2 x i16> %y
}
lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
324 ↗(On Diff #169517)

Should we just generate an ANY_EXTEND_VECTOR_INREG directly here?

Add a test case for AArch64. I wasn't sure what file to put it in so I made a new file and put the diff of the old vs new code here.

craig.topper added inline comments.Oct 20 2018, 10:53 PM
lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
324 ↗(On Diff #169517)

I don't think I can. I don't have any guarantee of vectors of the same size here.

efriedma accepted this revision.Oct 29 2018, 4:10 PM

LGTM

lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
324 ↗(On Diff #169517)

Oh, good point. It looks like they are in the cases you've shown, but maybe not in general.

This revision is now accepted and ready to land.Oct 29 2018, 4:10 PM
This revision was automatically updated to reflect the committed changes.