This is an archive of the discontinued LLVM Phabricator instance.

[PATCH]Select wide immediate offset into [Base+XReg] addressing mode
ClosedPublic

Authored by HaoLiu on Sep 24 2014, 3:48 AM.

Details

Summary

Hi Tim and other reviewers,

A base register plus a wide immediate offset may not be encoded by [Base+immediate] addressing mode or ADD/SUB instructions. Currently it will be selected into [Base+0] addressing mode and generate following instructions:

MOV  X0, WideImmediate
ADD  X1, BaseReg, X0
LDR  X2, [X1, 0]

But actually we can save one ADD by generating following instructions:

MOV  X0, WideImmediate
LDR  X2, [BaseReg, X0]

Review please.

Thanks,
-Hao

Diff Detail

Event Timeline

HaoLiu updated this revision to Diff 14026.Sep 24 2014, 3:48 AM
HaoLiu retitled this revision from to [PATCH]Select wide immediate offset into [Base+XReg] addressing mode.
HaoLiu updated this object.
HaoLiu edited the test plan for this revision. (Show Details)
HaoLiu added a reviewer: t.p.northover.
HaoLiu added a subscriber: Unknown Object (MLST).

ping...

Thanks,
-Hao

mcrosier added inline comments.Sep 30 2014, 7:01 AM
lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
780

Please make this a static function.
Functions should be in camel case and start with a lower case letter.
No particularly fond of the name. How about "isPreferredXROImm" or something of that nature? (Not sold on this either, but I think it's a step in the right direction.)

834

No need for SmallVector + push_back.

SDValue Ops[] = { RHS };

842

Don't we want to keep this bit of logic? (lines 789-793)


We don't want to match immediate adds here, because they are better lowered ​
to the register-immediate addressing modes. ​
if (isa<ConstantSDNode>(LHS) || isa<ConstantSDNode>(RHS))

return false;
test/CodeGen/AArch64/arm64-addrmode.ll
182

Please add a newline.

HaoLiu updated this revision to Diff 14552.Oct 8 2014, 2:16 AM

Hi Chad,

Thanks for the comments. I've attached a new patch according to your comments.

Thanks,
-Hao

mcrosier added inline comments.Oct 8 2014, 8:41 AM
lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
789

Thanks for the update, Hao. I'm still particularly concerned that this bit of logic is being removed entirely. Can you please elaborate on why this is being removed?

Hi Chad,

I think

Thanks,
-Hao

lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
789

Sure.

Firstly, only RHS can be constant. There is no situation that both LHS and RHS are constants (Such ADD will be optimized). Also, when there is only one constant operand in ADD, it will always adjust the constant to the RHS operand (See the test in my patch @t9). So my patch, only checks whether RHS is a constant node.

Then, the original logic checks and returns when the operand is constant. My patch improves this logic. When the constant is too wide to be encoded in [Register+Immdediate] addressing mode or in ADD/SUB, it will be selected in [Register+Register] addressing mode. Otherwise, it will still return false as original logic.

Thanks,
-Hao

842

I think there is no need keep such logic. This patch will check whether the ADD can be matched by the register-immediate addressing modes, if so, it will return false and do nothing.
See the if statement:

if ((ImmOff % Size == 0 && ImmOff >= 0 && ImmOff < (0x1000 << Scale))

Hi Chad,

I think the logic about

if (isa<ConstantSDNode>(LHS) || isa<ConstantSDNode>(RHS))

can be removed as following reasons:

Firstly, only RHS can be constant. There is no situation that both LHS and RHS are constants (Such ADD will be optimized). Also, when there is only one constant operand in ADD, it will always adjust the constant to the RHS operand (See the test in my patch @t9). So my patch, only checks whether RHS is a constant node.

Then, the original logic checks and returns when the operand is constant. My patch improves this logic. When the constant is too wide to be encoded in [Register+Immdediate] addressing mode or in ADD/SUB, it will be selected in [Register+Register] addressing mode. Otherwise, it will still return false as original logic.

Is that make sense?

Thanks,
-Hao

mcrosier accepted this revision.Oct 13 2014, 6:46 AM
mcrosier added a reviewer: mcrosier.
mcrosier added inline comments.
lib/Target/AArch64/AArch64ISelDAGToDAG.cpp
789

Now I understand; the old logic was misleading. If the constant is always canonicalized to the RHS, then this LGTM.

test/CodeGen/AArch64/arm64-addrmode.ll
97

Ok, constant always canonicalized to RHS.

This revision is now accepted and ready to land.Oct 13 2014, 6:46 AM
mcrosier closed this revision.Oct 14 2014, 3:25 PM

Hao committed r219665.