This is an archive of the discontinued LLVM Phabricator instance.

Canonicalize splats as build_vectors (PR22283)
ClosedPublic

Authored by spatel on Feb 3 2015, 1:29 PM.

Details

Summary

This is a minimal follow-on patch to:
http://reviews.llvm.org/D7093

That patch canonicalized constant splats as build_vectors, and this patch just removes the constant check so we can canonicalize all splats as build_vectors.

This fixes the 2nd test case in PR22283 ( http://llvm.org/bugs/show_bug.cgi?id=22283 ).

The unfortunate code duplication between SelectionDAG and DAGCombiner is discussed in the earlier patch. At least this patch is just removing code...

This improves an existing x86 AVX test and changes codegen in an ARM test. I don't know enough about ARM implementations to know if the new codegen is an improvement or not.

For the changed ARM tests, we currently generate something like this:

ldrsh	r12, [sp]   <--- load scalar
vmov	d17, r2, r3
vmov	d16, r0, r1
vmov	s0, r12
vcvt.f32.s32	s0, s0
vdup.32	q9, d0[0]     <--- splat register value
vsub.f32	q8, q9, q8
vmov	r0, r1, d16
vmov	r2, r3, d17
mov	pc, lr

With this patch, we'll generate a 'vld1' to splat instead:

mov	r12, sp
vmov	d19, r2, r3
vld1.16	{d16[]}, [r12:16] <--- load and splat
vmov	d18, r0, r1
vmovl.s16	q8, d16
vcvt.f32.s32	q8, q8
vsub.f32	q8, q8, q9
vmov	r0, r1, d16
vmov	r2, r3, d17
mov	pc, lr

Diff Detail

Repository
rL LLVM

Event Timeline

spatel updated this revision to Diff 19261.Feb 3 2015, 1:29 PM
spatel retitled this revision from to Canonicalize splats as build_vectors (PR22283).
spatel updated this object.
spatel edited the test plan for this revision. (Show Details)
spatel added reviewers: rengolin, andreadb, mkuper, RKSimon.
spatel added a subscriber: Unknown Object (MLST).
mkuper edited edge metadata.Feb 3 2015, 1:44 PM

From the x86 point of view, LGTM with a small nit.
Can't help you with ARM code quality, though.

lib/CodeGen/SelectionDAG/SelectionDAG.cpp
1563 ↗(On Diff #19261)

There's a missing space after the =.

spatel added inline comments.Feb 3 2015, 1:46 PM
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
1563 ↗(On Diff #19261)

That was an 80-column hack...so close. :)

andreadb accepted this revision.Feb 4 2015, 3:37 AM
andreadb edited edge metadata.

Hi Sanjay,

the patch LGTM.
However, somebody should review the codegen change in the ARM test.

lib/CodeGen/SelectionDAG/SelectionDAG.cpp
1563 ↗(On Diff #19261)

There are two places where we check for the BUILD_VECTOR value type. One is here at line 1563, the other one is at line 1567. If you evaluate 'BV->getValueType(0)' before the call to 'getNode' (line 1563), then you can reuse it and it will fit in the 80-cols.

This revision is now accepted and ready to land.Feb 4 2015, 3:37 AM
spatel updated this revision to Diff 19323.Feb 4 2015, 9:42 AM
spatel edited edge metadata.

Thanks, Andrea. Minor update to use local VT var; patch rebased against r228149.

spatel added a reviewer: asl.Feb 4 2015, 9:44 AM

Adding Anton as potential reviewer of the ARM change.

rengolin edited edge metadata.

Adding James, as he knows a lot more about NEON than I do.

spatel updated this revision to Diff 19330.Feb 4 2015, 9:58 AM
spatel edited edge metadata.

Added the missing space...really this time.

Ping.

ARM experts: is 'vld1' any better / worse than 'vdup' here?

jmolloy accepted this revision.Feb 17 2015, 2:12 AM
jmolloy edited edge metadata.

LGTM - splatting ld1 is better than ldrsh/vdup (at least from an architectural standpoint).

This revision was automatically updated to reflect the committed changes.