This is an archive of the discontinued LLVM Phabricator instance.

[RFC]Make the canonicalisation on shifts benifit to more case.
ClosedPublic

Authored by jojo on Dec 19 2016, 1:29 AM.

Details

Summary

Do canonicalisation on cases similar to below also profitable,
except on cases in "shift-or/xor/and/add-shift" context.

define i32 @test(i32 %v) {
entry:

%a = and i32 %v, 65534
%b = lshr i32 %a, 1
%c = and i32 %v, 65535
%d = lshr i32 %c, 1
%e = add i32 %b, %d
ret i32 %e

}

Diff Detail

Repository
rL LLVM

Event Timeline

jojo updated this revision to Diff 81925.Dec 19 2016, 1:29 AM
jojo retitled this revision from to [RFC]Make the canonicalisation on shifts benifit to more case..
jojo updated this object.
jojo added subscribers: llvm-commits, test.
rengolin added inline comments.Dec 19 2016, 8:34 AM
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
4557 ↗(On Diff #81925)

This if is getting a bit bloated. I think we should create a few boolean variables with names.

Something like:

auto Opc = BinOpLHSVal->getOpcode();
bool isShift = (Opc == ISD::SHL ...);
bool isConstantOp = isa<ConstantSDNode>(BinOpLHSVal->getOperand(1);
bool isCopyOrSelect = (Opc == ISD::CopyFromReg ...);

if ((!isShift || !isConstantOp) && !isCopyOrSelect)
  ...
jojo updated this revision to Diff 82198.Dec 20 2016, 9:50 PM
  1. Change according to inline comments
  2. Create tests for this change on ARM
  3. Some changes on the check line of Thumb2/machine-licm.ll, new canonicalisation will lead the tests to different instructions sequence.
rengolin accepted this revision.Dec 21 2016, 4:22 AM
rengolin edited edge metadata.

Thanks Jojo! I have a few nitpicks, but it's good to commit with those fixes.

lib/CodeGen/SelectionDAG/DAGCombiner.cpp
4548 ↗(On Diff #82198)

Is this still a FIXME? I think this comment could be just about what you're avoiding here, since it should have fixed the pessimized case, no?

4557 ↗(On Diff #81925)

This is looking much better, thanks!

test/CodeGen/ARM/shift-combine.ll
6 ↗(On Diff #82198)

It would be good, at least as documentation, to CHECK for the instructions you want to see. Same on the case below.

This revision is now accepted and ready to land.Dec 21 2016, 4:22 AM
jojo updated this revision to Diff 82316.Dec 22 2016, 1:42 AM
jojo edited edge metadata.
jojo added inline comments.
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
4548 ↗(On Diff #82198)

Indeed,it has fixed the pessimized case mentioned in the original FIXME. But I'm afraid there are other profitable cases that are not covered here. So I wonder if it is more clearer leaving a FIXME here.

test/CodeGen/ARM/shift-combine.ll
6 ↗(On Diff #82198)

Agree.That would be better.

This revision was automatically updated to reflect the committed changes.