This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Port buildvector -> dup pattern from AArch64ISelLowering
ClosedPublic

Authored by paquette on Jun 16 2020, 4:09 PM.

Details

Summary

Given this:

%x:_(<n x sK>) = G_BUILD_VECTOR %lane, ...
...
%y:_(<n x sK>) = G_SHUFFLE_VECTOR %x(<n x sK>), %foo, shufflemask(0, 0, ...)

We can produce:

%y:_(<n x sK) = G_DUP %lane(sK)

Doesn't seem to be too common, but AArch64ISelLowering attempts to do this before trying to produce a DUPLANE. Might as well port it.

Factor out the other G_DUP pattern into a helper function, and create a helper for this pattern.

Also make it so that when the splat has an undef mask, we try setting it to 0. SDAG does this, and it makes sure that when we get the build vector operand, we actually get a source operand.

Diff Detail

Event Timeline

paquette created this revision.Jun 16 2020, 4:09 PM

What's the reason for avoiding matching a constant lane build_vector?

llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
290

misleading whitespace change.

What's the reason for avoiding matching a constant lane build_vector?

I think that it's probably this comment in arm64-dup.ll:

; We used to spot this as a BUILD_VECTOR implementable by dup, but assume that
; the single value needed was of the same type as the vector. This is false if
; the scalar corresponding to the vector type is illegal (e.g. a <4 x i16>
; BUILD_VECTOR will have an i32 as its source). In that case, the operation is
; not a simple "dup vD.4h, vN.h[idx]" after all, and we crashed.
;
; *However*, it is a dup vD.4h, vN.h[2*idx].

This is wrt the following IR:

define <4 x i16> @test_build_illegal(<4 x i32> %in) {
  %val = extractelement <4 x i32> %in, i32 3
  %smallval = trunc i32 %val to i16
  %vec = insertelement <4x i16> undef, i16 %smallval, i32 3
  ret <4 x i16> %vec
}

So is this still applicable to GISel? If not can we remove that restriction.

paquette updated this revision to Diff 271864.Jun 18 2020, 3:53 PM
paquette edited the summary of this revision. (Show Details)
  • Remove restriction on constants. I don't think that we can have any problems here.
  • Fix whitespace in comment
aemerson accepted this revision.Jun 22 2020, 6:25 PM

LGTM.

This revision is now accepted and ready to land.Jun 22 2020, 6:25 PM
This revision was automatically updated to reflect the committed changes.