This is an archive of the discontinued LLVM Phabricator instance.

[AArch64][SVE] Implement element count intrinsics
ClosedPublic

Authored by c-rhodes on Dec 3 2019, 9:12 AM.

Details

Summary

Adds intrinsics for the following:

  • cntb
  • cnth
  • cntw
  • cntd
  • cntp

Event Timeline

c-rhodes created this revision.Dec 3 2019, 9:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2019, 9:12 AM
efriedma added inline comments.Dec 3 2019, 4:40 PM
llvm/include/llvm/IR/IntrinsicsAArch64.td
937

What is LLVMScalarOrSameVectorWidth<0, llvm_i1_ty> supposed to do here? Why not just LLVMMatchType?

llvm/test/CodeGen/AArch64/sve-intrinsics-counting-elems.ll
11

No operand for the MUL immediate? I guess you could try to pattern-match it, but that seems less reliable.

c-rhodes added inline comments.Dec 4 2019, 4:24 AM
llvm/include/llvm/IR/IntrinsicsAArch64.td
937

Downstream CNTP/SADDV/UADDV share the same implementation, I agree reading the definition it's misleading (I would expect a type signature that looks like SADDV/UADDV). I'll change this to LLVMMatchType.

llvm/test/CodeGen/AArch64/sve-intrinsics-counting-elems.ll
11

These intrinsics are a reflection of the ACLE intrinsics which don't expose the multiplier for two reasons I guess: 1) at the C and C++ level it's usually simpler to write the multiply out as normal, e.g. svcntw() * 3;, and 2) the compiler should be able to fold a suitable multiply in.

We have a separate patch downstream I'll follow up with to support this:

define i64 @cntb_mul3() {
; CHECK-LABEL: cntb_mul3:
; CHECK: cntb x0, vl6, mul #3
; CHECK-NEXT: ret
  %cnt = call i64 @llvm.aarch64.sve.cntb(i32 6)
  %out = mul i64 %cnt, 3
  ret i64 %out
}
c-rhodes updated this revision to Diff 232089.Dec 4 2019, 4:51 AM

Use LLVMMatchType in CNTP intrinsic definition.

c-rhodes marked an inline comment as done.Dec 4 2019, 4:52 AM
efriedma accepted this revision.Dec 4 2019, 4:49 PM

LGTM

This revision is now accepted and ready to land.Dec 4 2019, 4:49 PM
This revision was automatically updated to reflect the committed changes.