This is an archive of the discontinued LLVM Phabricator instance.

[ARM,MVE] Add reversed isel patterns for MVE `vcmp qN,rN`
ClosedPublic

Authored by simon_tatham on Nov 15 2019, 1:59 AM.

Details

Summary

As well as vector/vector compare instructions, MVE also has a family
of comparisons taking a vector and a scalar, which compare every lane
of the vector against the same value. We generate those at isel time
using isel patterns that match (ARMvcmp vector, (ARMvdup scalar)).

This commit adds corresponding patterns for the operand-reversed form
(ARMvcmp (ARMvdup scalar), vector), with condition codes swapped as
necessary. That way, we can still generate the vector/scalar compare
instruction if the IR happens to have been rearranged to put the
operands the other way round, which can happen in some optimization
phases. Previously, a vcmp the other way round was handled by emitting
a vdup instruction to explicitly replicate the scalar input into
a vector, and then doing a vector/vector comparison.

I haven't added a new test, because it turned out that several
existing tests were already exhibiting that failure mode. So just
updating the expected output in the existing MVE codegen tests
demonstrates what's been improved.

Diff Detail

Event Timeline

simon_tatham created this revision.Nov 15 2019, 1:59 AM
dmgreen accepted this revision.Nov 15 2019, 5:54 AM

Oh OK. I was assuming this would be done in DAG2DAG, where it would attempt to canonicalise vdups or 0's to the right of a vcmp. And then do any folding or whathaveyou to try and come up with a sequence of instructions that would end up being selected nicely (turning Ors into Ands and such).

It can be done in tablegen pattern though, that sounds OK. We might eventually want to put it in DAG2DAG as well, as it will likely be doing similar things anyway.

LGTM. Looks like a nice improvement.

This revision is now accepted and ready to land.Nov 15 2019, 5:54 AM
This revision was automatically updated to reflect the committed changes.