This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Swap cmp operands for automatic shifts.
ClosedPublic

Authored by samparker on Oct 17 2017, 8:04 AM.

Details

Summary

Swap the compare operands if the lhs is a shift and the rhs isn't, as in arm and T2 the shift can be performed by the compare for its second operand.

Diff Detail

Event Timeline

samparker created this revision.Oct 17 2017, 8:04 AM
efriedma added inline comments.
lib/Target/ARM/ARMISelLowering.cpp
3861

Whitespace.

test/CodeGen/ARM/cmp-shift-swap.ll
12 ↗(On Diff #119324)

We already have some related tests in test/CodeGen/Thumb2/thumb2-cmp2.ll; could you combine these into the same file?

Please include a testcase for a rotate.

samparker updated this revision to Diff 119443.Oct 18 2017, 2:03 AM

Thanks Eli, I've made your suggested changes.

By "combine", I meant we should end up with one file, run in both ARM and Thumb mode; duplicating the tests just makes it more confusing.

samparker updated this revision to Diff 119817.Oct 23 2017, 1:35 AM

Now using a single test file for arm and thumb2 compares.

efriedma added inline comments.Oct 23 2017, 3:07 PM
lib/Target/ARM/ARMISelLowering.cpp
3869

Wait a sec.

In IR, we have two related, but distinct methods on comparisons: getInversePredicate, and getSwappedPredicate. Similarly, in SelectionDAG we have getSetCCInverse and getSetCCSwappedOperands. ARMCC::getOppositeCondition is equivalent to getInversePredicate, but I think you want getSwappedPredicate here?

And given that oversight, I have to ask: how did you test this?

samparker added inline comments.Oct 24 2017, 1:52 AM
lib/Target/ARM/ARMISelLowering.cpp
3869

Very badly it seems.

Thanks for catching this and sorry for making the dumb mistake. I'll use the SwappedOperands function and add some vital checks to the tests.

Thanks again.

samparker updated this revision to Diff 120027.Oct 24 2017, 3:01 AM

Now using getSetCCSwappedOperands to fix the condition code issue. Also added checks to the tests to inspect the condition codes used.

This revision is now accepted and ready to land.Oct 24 2017, 5:44 PM
This revision was automatically updated to reflect the committed changes.
test/CodeGen/ARM/cmp.ll