This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][GlobalISel] Implement custom legalization for s32/s64 G_FCOPYSIGN
ClosedPublic

Authored by paquette on Aug 25 2021, 1:28 PM.

Details

Summary

This is intended to be equivalent to the s32 + s64 cases in AArch64TargetLowering::LowerFCOPYSIGN.

Widen everything and then use G_BIT + a mask to handle the actual copysign operation. Then, narrow back down to s32/s64.

I wasn't sure about what the best/most canonical INSERT_SUBREG-selectable pattern is. I chose G_INSERT_VECTOR_ELT + an undef vector because it produces reasonably okay codegen. (It doesn't produce INSERT_SUBREG right now though.) If there's a better way to do this then I'm happy to change it.

We also have a couple codegen deficiencies with how we emit vector constants right now. (We need a GISel equivalent to the tryAdvSIMDModImm64 stuff)

Diff Detail

Event Timeline

paquette created this revision.Aug 25 2021, 1:28 PM
paquette requested review of this revision.Aug 25 2021, 1:28 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 25 2021, 1:28 PM
aemerson added inline comments.Aug 25 2021, 3:42 PM
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
1470

What if we use G_MERGE instead? Do we get an INSERT_SUBREG?

This comment was removed by paquette.
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
1470

Not quite.

We get the following for s32 with G_MERGE_VALUES:

legalize_s32:
	adrp	x8, .LCPI0_0
	mov	v0.s[1], v0.s[0]
	mov	v1.s[1], v0.s[0]
	ldr	q2, [x8, :lo12:.LCPI0_0]
	mov	v0.s[2], v0.s[0]
	mov	v0.s[3], v0.s[0]
	mov	v1.s[2], v0.s[0]
	mov	v1.s[3], v0.s[0]
	bit	v0.16b, v1.16b, v2.16b
	ret

Meanwhile, with SDAG we get

	movi	v2.4s, #128, lsl #24 ; We should emit the constant like this, but we don't have that optimization
	bit	v0.16b, v1.16b, v2.16b
	ret

We can probably change the selector code to recognize the pattern though. Using G_INSERT_VECTOR_ELT is only slightly better.

aemerson accepted this revision.Aug 25 2021, 9:17 PM
aemerson added inline comments.
llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp
1470

Ok, let's go with the insert for now.

This revision is now accepted and ready to land.Aug 25 2021, 9:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 28 2022, 4:03 PM