This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Add new subtarget feature to fold LSL into address mode.
ClosedPublic

Authored by bmakam on Mar 17 2017, 8:46 PM.

Details

Summary

This feature enables folding of logical shift operations of up to 3 places into addressing mode on Kryo and Falkor that have a fastpath LSL.

PTAL,
Balaram

Diff Detail

Repository
rL LLVM

Event Timeline

bmakam created this revision.Mar 17 2017, 8:46 PM
gberry added a subscriber: gberry.Mar 18 2017, 11:55 AM
junbuml added inline comments.Mar 20 2017, 7:44 AM
lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
337 ↗(On Diff #92244)

Don't we need to add assert( V.getOpcode() == ISD::SHL ) ?

342 ↗(On Diff #92244)

It will be good to add a test for this case.

347 ↗(On Diff #92244)

I think "Subtarget->hasLSLFast()" need to be check earlier. Maybe in isWorthFolding() ?

369 ↗(On Diff #92244)

Why not doing this first.

mcrosier added inline comments.Mar 20 2017, 9:19 AM
lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
347 ↗(On Diff #92244)

+1

bmakam updated this revision to Diff 92539.Mar 21 2017, 1:56 PM

Address Jun's comments.

bmakam marked 5 inline comments as done.Mar 21 2017, 1:57 PM
mcrosier added inline comments.Mar 23 2017, 12:03 PM
lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
335 ↗(On Diff #92539)

Shouldn't we be returning false if the 1st operand isn't a constant?

I guess I would expect something like:

if (!isa<ConstantSDNode>(V.getOperand(1)))
  return false;

auto *CSD = cast<ConstantSDNode>(V.getOperand(1))
unsigned ShiftVal = CSD->getZExtValue();
  if (ShiftVal > 3)
    return false;

...
bmakam updated this revision to Diff 92859.Mar 23 2017, 1:31 PM

Address Chad's comments.

bmakam marked an inline comment as done.Mar 23 2017, 1:32 PM
mcrosier accepted this revision.Mar 27 2017, 8:54 AM

LGTM, with a few nits.

lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
331 ↗(On Diff #92859)

worth it to fold the SHL into the addressing mode.

339 ↗(On Diff #92859)

I'm not a huge fan of the magic number, but I think it's reasonable to leave as is until another target uses this feature.

360 ↗(On Diff #92859)

we can fold a logical shift into the addressing mode

365 ↗(On Diff #92859)

Are there other interesting binary operators besides ADD?

This revision is now accepted and ready to land.Mar 27 2017, 8:54 AM
bmakam marked 2 inline comments as done.Mar 31 2017, 9:23 AM

Thanks for the review Chad,
If there is no objection from others, I will commit this change with the fixes for your comments.

lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
365 ↗(On Diff #92859)

One case that is currently not handled by this is when we have extend, for example we fail to fold a logical shift into the addressing mode in the test below for aarch64:

define i32 @test3(i32 %base, i32 %base2, i32 %offset) {
entry:
        %tmp1 = shl i32 %offset, 2
        %tmp2 = add i32 %base, %tmp1
        %tmp3 = inttoptr i32 %tmp2 to i32*
        %tmp4 = add i32 %base2, %tmp1
        %tmp5 = inttoptr i32 %tmp4 to i32*
        %tmp6 = load i32, i32* %tmp3
        %tmp7 = load i32, i32* %tmp5
        %tmp8 = add i32 %tmp7, %tmp6
        ret i32 %tmp8
}

I think this will have to be fixed in a separate change.

This revision was automatically updated to reflect the committed changes.