Skip to content

Commit 0d94b63

Browse files
committed
[IR] Add LLVM IR support for target("aarch64.svcount") type.
The C and C++ Language Extensions for AArch64 SME2 [1] adds a new type called `svcount_t` which describes a predicate. This is not a predicate vector mask, but rather a description of a predicate vector mask that can be expanded into a mask using explicit instructions. The type is a scalable opaque type. To implement `svcount_t` type this patch uses the existing Target Extension Type mechanism, but adds further support so that this type can be a scalable type. AArch64 CodeGen support will follow in a separate patch. [1] ARM-software/acle#217 Reviewed By: jcranmer-intel, nikic Differential Revision: https://reviews.llvm.org/D136861
1 parent 475417b commit 0d94b63

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

llvm/docs/AArch64SME.rst

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,38 @@ Committing a lazy-save
440440
Exception handling and ZA
441441
-------------------------
442442

443-
4. References
443+
4. Types
444+
========
445+
446+
AArch64 Predicate-as-Counter Type
447+
---------------------------------
448+
449+
:Overview:
450+
451+
The predicate-as-counter type represents the type of a predicate-as-counter
452+
value held in a AArch64 SVE predicate register. Such a value contains
453+
information about the number of active lanes, the element width and a bit that
454+
tells whether the generated mask should be inverted. ACLE intrinsics should be
455+
used to move the predicate-as-counter value to/from a predicate vector.
456+
457+
There are certain limitations on the type:
458+
459+
* The type can be used for function parameters and return values.
460+
461+
* The supported LLVM operations on this type are limited to ``load``, ``store``,
462+
``phi``, ``select`` and ``alloca`` instructions.
463+
464+
The predicate-as-counter type is a scalable type.
465+
466+
:Syntax:
467+
468+
::
469+
470+
target("aarch64.svcount")
471+
472+
473+
474+
5. References
444475
=============
445476

446477
.. _aarch64_sme_acle:

llvm/lib/IR/Type.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,11 @@ static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
863863
return TargetTypeInfo(Type::getInt8PtrTy(C, 0), TargetExtType::HasZeroInit,
864864
TargetExtType::CanBeGlobal);
865865
}
866+
867+
// Opaque types in the AArch64 name space.
868+
if (Name == "aarch64.svcount")
869+
return TargetTypeInfo(ScalableVectorType::get(Type::getInt1Ty(C), 16));
870+
866871
return TargetTypeInfo(Type::getVoidTy(C));
867872
}
868873

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -passes='instcombine' -S < %s | FileCheck %s
3+
4+
define target("aarch64.svcount") @test_alloca_store_reload(target("aarch64.svcount") %val) nounwind {
5+
; CHECK-LABEL: @test_alloca_store_reload(
6+
; CHECK-NEXT: ret target("aarch64.svcount") [[VAL:%.*]]
7+
;
8+
%ptr = alloca target("aarch64.svcount"), align 1
9+
store target("aarch64.svcount") %val, ptr %ptr
10+
%res = load target("aarch64.svcount"), ptr %ptr
11+
ret target("aarch64.svcount") %res
12+
}
13+
14+
; Test that instcombine doesn't try to query the (scalable) size of target("aarch64.svcount")
15+
; in foldSelectInstWithICmp.
16+
define target("aarch64.svcount") @test_combine_on_select(target("aarch64.svcount") %x, target("aarch64.svcount") %y, i32 %k) {
17+
; CHECK-LABEL: @test_combine_on_select(
18+
; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[K:%.*]], 42
19+
; CHECK-NEXT: [[X_Y:%.*]] = select i1 [[CMP]], target("aarch64.svcount") [[X:%.*]], target("aarch64.svcount") [[Y:%.*]]
20+
; CHECK-NEXT: ret target("aarch64.svcount") [[X_Y]]
21+
;
22+
%cmp = icmp sgt i32 %k, 42
23+
%x.y = select i1 %cmp, target("aarch64.svcount") %x, target("aarch64.svcount") %y
24+
ret target("aarch64.svcount") %x.y
25+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -passes='sroa' -S < %s | FileCheck %s
3+
4+
define target("aarch64.svcount") @test_alloca_store_reload(target("aarch64.svcount") %val) nounwind {
5+
; CHECK-LABEL: @test_alloca_store_reload(
6+
; CHECK-NEXT: ret target("aarch64.svcount") [[VAL:%.*]]
7+
;
8+
%ptr = alloca target("aarch64.svcount"), align 1
9+
store target("aarch64.svcount") %val, ptr %ptr
10+
%res = load target("aarch64.svcount"), ptr %ptr
11+
ret target("aarch64.svcount") %res
12+
}

0 commit comments

Comments
 (0)