This is an archive of the discontinued LLVM Phabricator instance.

[ARM,MVE] Add intrinsics for vector comparisons.
ClosedPublic

Authored by simon_tatham on Nov 15 2019, 2:00 AM.

Details

Summary

This adds the vcmp family of ACLE MVE intrinsics: vector/vector,
vector/scalar, and the predicated forms of both. All are represented
using standard existing IR: vector/scalar comparisons are represented
by making a vector out of the scalar first, and predicated forms are
represented by taking the bitwise AND of the input predicate and the
output of the comparison. Existing LLVM-side tests demonstrate that
ISel will pattern-match all of that back down to single MVE VCMPs.

The idiom of handling a vector/scalar operation by generating IR to
expand the scalar into a second vector is going to be needed for a lot
of MVE intrinsics, so to make that easy, I've provided a helper
function that automatically works out the element count.

The comparison intrinsics are the first ones that have to return a
predicate, in the user-facing mve_pred16_t format. This means we
have to use the arm_mve_pred_v2i low-level intrinsic to convert it
back from the logical <n x i1> form used in IR. I've done that
explicitly in the code gen specification for the builtins, because it
happens much more rarely in the ACLE API than passing a Predicate as
input, so it didn't seem worth automating in MveEmitter.

Diff Detail

Event Timeline

simon_tatham created this revision.Nov 15 2019, 2:00 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 15 2019, 2:00 AM
dmgreen added inline comments.Nov 15 2019, 5:30 AM
clang/lib/CodeGen/CGBuiltin.cpp
6798

Is this the same as or similar enough to CreateVectorSplat to use that instead?

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
3311 ↗(On Diff #229477)

This can be a separate change.

simon_tatham marked 2 inline comments as done.Nov 15 2019, 6:11 AM
simon_tatham added inline comments.
clang/lib/CodeGen/CGBuiltin.cpp
6798

Ah, thank you – I can see why I didn't find it under that name! I looked for all sorts of things like "dup" or "rep", and then gave up and painstakingly copied the long-winded IR I'd seen in an existing example. "splat" is one of those words you have no trouble finding after you know it's the word you're looking for...

Now I know there's an existing function that will do the job, I agree that I should use it (if only because it'll produce the most idiomatic one of the various synonymous IR representations). But I think I'll keep the wrapping helper function, because it's still useful to have it auto-compute the unique correct element count for an MVE vector – that will keep the call sites terse in arm_mve.td, and I expect there will be lots of those.

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
3311 ↗(On Diff #229477)

OK, will do.

Replaced my laborious manual vector splat with a call to the standard one; moved the InstCombine work out into a separate patch.

simon_tatham edited the summary of this revision. (Show Details)Nov 15 2019, 7:26 AM
simon_tatham edited the summary of this revision. (Show Details)

D'oh, moved mve-vpt-from-intrinsics.ll into D70313.

Harbormaster completed remote builds in B41031: Diff 229549.
dmgreen accepted this revision.Nov 18 2019, 2:00 AM

LGTM

This revision is now accepted and ready to land.Nov 18 2019, 2:00 AM
This revision was automatically updated to reflect the committed changes.
clang/lib/CodeGen/CGBuiltin.cpp