This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Try to fold lsl + ldr/str
Needs ReviewPublic

Authored by jaykang10 on Dec 3 2021, 1:31 AM.

Details

Summary

On ISelDAG level, if there are multiple uses of lsl, the ldr/str, which are uses of the lsl, are not folded.
Additionaly, if the lsl is not in same block with ldr/str, they are not folded too.
ldr/str can be folded with lsl 2 for 32 bit and lsl 3 for 64 bit as below.

%7:gpr64 = UBFMXri killed %6:gpr64, 62, 61
%8:gpr32 = LDRWroX %1:gpr64common, %7:gpr64, 0, 0
STRWroX killed %9:gpr32, %1:gpr64common, %7:gpr64, 0, 0
==>
%8:gpr32 = LDRWroX %1:gpr64common, %6:gpr64, 0, 1
STRWroX killed %9:gpr32, %1:gpr64common, %6:gpr64, 0, 1

Diff Detail

Event Timeline

jaykang10 created this revision.Dec 3 2021, 1:31 AM
jaykang10 requested review of this revision.Dec 3 2021, 1:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2021, 1:31 AM

Could this just update the code in https://github.com/llvm/llvm-project/blob/1f5510326375cb9a7c747aab26080699f7952d74/llvm/lib/Target/AArch64/AArch64ISelDAGToDAG.cpp#L510?

It sounds like FeatureLSLFast could be more generally enabled, depending on what the conditions are for when this is fast.

Ah, you are right! It looks the isWorthFoldingSHL is doing same thing and it will work within a block.
However, if the lsl is in different block with the ldr/str, it would not work because there would be CopyFromReg for lsl in the block of ldr/str.

It sounds like FeatureLSLFast could be more generally enabled, depending on what the conditions are for when this is fast.

Yep, I agree with you. At least, we need to enable it for neoverse.