Page MenuHomePhabricator

[llvm][Aarch64][SVE] Remove extra fmov instruction with certain literals
ClosedPublic

Authored by DavidTruby on Feb 15 2021, 4:09 AM.

Details

Summary

When a literal that cannot fit in the immediate form of the fmov instruction
is used to initialise an SVE vector, an extra unnecessary fmov is currently
generated. This patch adds an extra codegen pattern preventing the extra
instruction from being generated.

Diff Detail

Event Timeline

DavidTruby created this revision.Feb 15 2021, 4:09 AM
DavidTruby requested review of this revision.Feb 15 2021, 4:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 15 2021, 4:09 AM
georges added inline comments.
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
556

do we also need patterns for f16/f64?

paulwalker-arm accepted this revision.Feb 15 2021, 4:46 AM

Patch looks good to me. I'll leave it up to you whether you want to extend the patch to cover f16/f64 cases or defer until needed.

llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
556

I would say want rather than need given this is more optimisation than function.

llvm/test/CodeGen/AArch64/sve-intrinsics-dup-x.ll
133–139

Keep it if you want but this test "vscale x 2 x float" is kind of unnecessary because the intrinsics only expect to operate on/with fully packed vectors. The fact some work with unpacked types is really a quirk due to some reusing the ISD nodes used for stock LLVM IR.

This revision is now accepted and ready to land.Feb 15 2021, 4:46 AM

Added equivalent f64 patterns

The f64 case is similar enough that adding those patterns here is fine; f16 seems to take
a different codepath and generate very different code, so I'd rather change that separately
when it comes up (if it proves necessary).

DavidTruby marked an inline comment as done.Feb 15 2021, 5:32 AM
DavidTruby added inline comments.Feb 15 2021, 5:38 AM
llvm/test/CodeGen/AArch64/sve-intrinsics-dup-x.ll
133–139

If it's not likely to not be permitted in future I'd probably rather leave it in on the basis that more tests is usually just better in my opinion. I can remove if it's something that shouldn't be allowed/might not be allowed in future though

LGTM, I'll let @paulwalker-arm accept.

david-arm added inline comments.
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
557

It looks like this probably needs a
let AddedComplexity = 2
like the patterns below. Also, should we be also adding patterns for half and double too?

paulwalker-arm requested changes to this revision.Feb 15 2021, 6:10 AM
paulwalker-arm added inline comments.
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
563–564

nxv4f64 is not a legal type and thus this pattern will have no affect.

llvm/test/CodeGen/AArch64/sve-intrinsics-dup-x.ll
157–164

Whilst I can begrudgingly accept the vscale x 2 x float test, this vscale x 4 x double test should definite be removed as it is not linked to any of the new patterns.

llvm/test/CodeGen/AArch64/sve-vector-splat.ll
404–405

I'd remove this test also, but if you keep it then the CHECK lines need updating as <vscale x 4 x double> sits across two registers. Personally I just remove it as it's not testing anything that is not already tested by splat_nxv2f64_fmov_fold.

This revision now requires changes to proceed.Feb 15 2021, 6:10 AM
paulwalker-arm added inline comments.Feb 15 2021, 6:18 AM
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
557

@david-arm : What have you spotted to say this? The tests suggest AddedComplexity is not required?

david-arm added inline comments.Feb 15 2021, 6:21 AM
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
557

Well, I guess I haven't seen specific tests that require this. I just thought this was consistent with the patterns below that's all, but maybe I've just misunderstood something!

DavidTruby added inline comments.Feb 15 2021, 6:29 AM
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
557

Adding it seems to break a number of other unrelated tests so I think it's best to leave it out

563–564

My mistake I must have not been thinking very hard when I added these!

Remove faulty f64 patterns

DavidTruby marked 3 inline comments as done.Feb 15 2021, 6:34 AM
paulwalker-arm accepted this revision.Feb 15 2021, 6:41 AM
paulwalker-arm added inline comments.
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
559

Rouge intent.

This revision is now accepted and ready to land.Feb 15 2021, 6:41 AM
DavidTruby marked an inline comment as done.Feb 16 2021, 6:18 AM
DavidTruby added inline comments.
llvm/lib/Target/AArch64/AArch64SVEInstrInfo.td
559

fixed in committed version