This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Support all extend/shift op for pattern: (ExtendOrShfitNode - Y) + Z --> (Z - Y) + ExtendOrShfitNode
ClosedPublic

Authored by bcl5980 on Oct 31 2022, 4:24 AM.

Diff Detail

Event Timeline

bcl5980 created this revision.Oct 31 2022, 4:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2022, 4:24 AM
bcl5980 requested review of this revision.Oct 31 2022, 4:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 31 2022, 4:24 AM

Sounds good. Should we be handling uxtw and sxtw type operands too? As in getExtendTypeForNode.

bcl5980 updated this revision to Diff 472845.Nov 2 2022, 9:33 PM
bcl5980 retitled this revision from [AArch64] Support not only SHL but also SRL and SRA for ((X shift C) - Y) + Z --> (Z - Y) + (X shift C) to [AArch64] Support all extend op pattern for (ExtendNode - Y) + Z --> (Z - Y) + ExtendNode .
bcl5980 edited the summary of this revision. (Show Details)
bcl5980 updated this revision to Diff 472849.Nov 2 2022, 11:16 PM
bcl5980 retitled this revision from [AArch64] Support all extend op pattern for (ExtendNode - Y) + Z --> (Z - Y) + ExtendNode to [AArch64] Support all extend op for pattern: (ExtendNode - Y) + Z --> (Z - Y) + ExtendNode .

minor format update.

dmgreen added inline comments.Nov 8 2022, 1:25 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
16910

Perhaps change canbeExtend to isExtendOrShiftOperand, or something like it?

16915

Do you have tests for the other cases?

16928

What overflow are you thinking of? Shifting past the bitwidth?

bcl5980 added inline comments.Nov 8 2022, 1:46 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
16915

Not sure how to generate ISD::ANY_EXTEND/ISD::SIGN_EXTEND_INREG from llvm-ir. Can you give me some suggestions for that?

16928

Yeah, I'm not sure if we can do this when the shift amount is larger than bitwidth.

dmgreen added inline comments.Nov 8 2022, 2:49 AM
llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
16915

SIGN_EXTEND_INREG is usually lsl 48; ashr 48. Any extend can be difficult (especially if we expect the value to be used). Adding some extra 64bit tests would be useful too, for the different And cases for example.

bcl5980 updated this revision to Diff 473982.Nov 8 2022, 6:18 AM
bcl5980 retitled this revision from [AArch64] Support all extend op for pattern: (ExtendNode - Y) + Z --> (Z - Y) + ExtendNode to [AArch64] Support all extend/shift op for pattern: (ExtendOrShfitNode - Y) + Z --> (Z - Y) + ExtendOrShfitNode.
dmgreen accepted this revision.Nov 9 2022, 1:54 AM

Thanks. From what I can tell this looks OK, and the performance should be better. LGTM

This revision is now accepted and ready to land.Nov 9 2022, 1:54 AM