Skip to content

Commit 0eca79f

Browse files
committed
Address comments
1 parent 453324a commit 0eca79f

File tree

3 files changed

+56
-42
lines changed

3 files changed

+56
-42
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11285,6 +11285,21 @@ Value *CodeGenFunction::EmitAArch64SMEBuiltinExpr(unsigned BuiltinID,
1128511285
if (Builtin->LLVMIntrinsic == 0)
1128611286
return nullptr;
1128711287

11288+
if (BuiltinID == SME::BI__builtin_sme___arm_in_streaming_mode) {
11289+
// If we already know the streaming mode, don't bother with the intrinsic
11290+
// and emit a constant instead
11291+
auto FD = cast<FunctionDecl>(CurFuncDecl);
11292+
if (const Type *Ty = FD->getType().getTypePtrOrNull())
11293+
if (const auto *FPT = Ty->getAs<FunctionProtoType>()) {
11294+
unsigned SMEAttrs = FPT->getAArch64SMEAttributes();
11295+
if (!(SMEAttrs & FunctionType::SME_PStateSMCompatibleMask)) {
11296+
bool IsStreamingMode =
11297+
SMEAttrs & FunctionType::SME_PStateSMEnabledMask;
11298+
return ConstantInt::getBool(Builder.getContext(), IsStreamingMode);
11299+
}
11300+
}
11301+
}
11302+
1128811303
// Predicates must match the main datatype.
1128911304
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
1129011305
if (auto PredTy = dyn_cast<llvm::VectorType>(Ops[i]->getType()))

clang/test/CodeGen/AArch64/sme-intrinsics/acle_sme_state_funs.c

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,53 @@
66

77
#include <arm_sme.h>
88

9-
// CHECK-LABEL: @test_in_streaming_mode(
9+
// CHECK-LABEL: @test_in_streaming_mode_streaming_compatible(
1010
// CHECK-NEXT: entry:
1111
// CHECK-NEXT: [[TMP0:%.*]] = tail call i1 @llvm.aarch64.sme.in.streaming.mode()
1212
// CHECK-NEXT: ret i1 [[TMP0]]
1313
//
14-
// CPP-CHECK-LABEL: @_Z22test_in_streaming_modev(
14+
// CPP-CHECK-LABEL: @_Z43test_in_streaming_mode_streaming_compatiblev(
1515
// CPP-CHECK-NEXT: entry:
1616
// CPP-CHECK-NEXT: [[TMP0:%.*]] = tail call i1 @llvm.aarch64.sme.in.streaming.mode()
1717
// CPP-CHECK-NEXT: ret i1 [[TMP0]]
1818
//
19-
bool test_in_streaming_mode(void) __arm_streaming_compatible {
19+
bool test_in_streaming_mode_streaming_compatible(void) __arm_streaming_compatible {
20+
return __arm_in_streaming_mode();
21+
}
22+
23+
// CHECK-LABEL: @test_in_streaming_mode_streaming(
24+
// CHECK-NEXT: entry:
25+
// CHECK-NEXT: ret i1 true
26+
//
27+
// CPP-CHECK-LABEL: @_Z32test_in_streaming_mode_streamingv(
28+
// CPP-CHECK-NEXT: entry:
29+
// CPP-CHECK-NEXT: ret i1 true
30+
//
31+
bool test_in_streaming_mode_streaming(void) __arm_streaming {
32+
//
33+
return __arm_in_streaming_mode();
34+
}
35+
36+
// CHECK-LABEL: @test_in_streaming_mode_non_streaming(
37+
// CHECK-NEXT: entry:
38+
// CHECK-NEXT: ret i1 false
39+
//
40+
// CPP-CHECK-LABEL: @_Z36test_in_streaming_mode_non_streamingv(
41+
// CPP-CHECK-NEXT: entry:
42+
// CPP-CHECK-NEXT: ret i1 false
43+
//
44+
bool test_in_streaming_mode_non_streaming(void) {
2045
return __arm_in_streaming_mode();
2146
}
2247

2348
// CHECK-LABEL: @test_za_disable(
2449
// CHECK-NEXT: entry:
25-
// CHECK-NEXT: tail call void @__arm_za_disable() #[[ATTR5:[0-9]+]]
50+
// CHECK-NEXT: tail call void @__arm_za_disable() #[[ATTR7:[0-9]+]]
2651
// CHECK-NEXT: ret void
2752
//
2853
// CPP-CHECK-LABEL: @_Z15test_za_disablev(
2954
// CPP-CHECK-NEXT: entry:
30-
// CPP-CHECK-NEXT: tail call void @__arm_za_disable() #[[ATTR5:[0-9]+]]
55+
// CPP-CHECK-NEXT: tail call void @__arm_za_disable() #[[ATTR7:[0-9]+]]
3156
// CPP-CHECK-NEXT: ret void
3257
//
3358
void test_za_disable(void) __arm_streaming_compatible {
@@ -36,14 +61,14 @@ void test_za_disable(void) __arm_streaming_compatible {
3661

3762
// CHECK-LABEL: @test_has_sme(
3863
// CHECK-NEXT: entry:
39-
// CHECK-NEXT: [[TMP0:%.*]] = tail call aarch64_sme_preservemost_from_x2 { i64, i64 } @__arm_sme_state() #[[ATTR5]]
64+
// CHECK-NEXT: [[TMP0:%.*]] = tail call aarch64_sme_preservemost_from_x2 { i64, i64 } @__arm_sme_state() #[[ATTR7]]
4065
// CHECK-NEXT: [[TMP1:%.*]] = extractvalue { i64, i64 } [[TMP0]], 0
4166
// CHECK-NEXT: [[TOBOOL_I:%.*]] = icmp slt i64 [[TMP1]], 0
4267
// CHECK-NEXT: ret i1 [[TOBOOL_I]]
4368
//
4469
// CPP-CHECK-LABEL: @_Z12test_has_smev(
4570
// CPP-CHECK-NEXT: entry:
46-
// CPP-CHECK-NEXT: [[TMP0:%.*]] = tail call aarch64_sme_preservemost_from_x2 { i64, i64 } @__arm_sme_state() #[[ATTR5]]
71+
// CPP-CHECK-NEXT: [[TMP0:%.*]] = tail call aarch64_sme_preservemost_from_x2 { i64, i64 } @__arm_sme_state() #[[ATTR7]]
4772
// CPP-CHECK-NEXT: [[TMP1:%.*]] = extractvalue { i64, i64 } [[TMP0]], 0
4873
// CPP-CHECK-NEXT: [[TOBOOL_I:%.*]] = icmp slt i64 [[TMP1]], 0
4974
// CPP-CHECK-NEXT: ret i1 [[TOBOOL_I]]
@@ -66,12 +91,12 @@ void test_svundef_za(void) __arm_streaming_compatible __arm_out("za") {
6691

6792
// CHECK-LABEL: @test_sc_memcpy(
6893
// CHECK-NEXT: entry:
69-
// CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memcpy(ptr noundef [[DEST:%.*]], ptr noundef [[SRC:%.*]], i64 noundef [[N:%.*]]) #[[ATTR5]]
94+
// CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memcpy(ptr noundef [[DEST:%.*]], ptr noundef [[SRC:%.*]], i64 noundef [[N:%.*]]) #[[ATTR7]]
7095
// CHECK-NEXT: ret ptr [[CALL]]
7196
//
7297
// CPP-CHECK-LABEL: @_Z14test_sc_memcpyPvPKvm(
7398
// CPP-CHECK-NEXT: entry:
74-
// CPP-CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memcpy(ptr noundef [[DEST:%.*]], ptr noundef [[SRC:%.*]], i64 noundef [[N:%.*]]) #[[ATTR5]]
99+
// CPP-CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memcpy(ptr noundef [[DEST:%.*]], ptr noundef [[SRC:%.*]], i64 noundef [[N:%.*]]) #[[ATTR7]]
75100
// CPP-CHECK-NEXT: ret ptr [[CALL]]
76101
//
77102
void *test_sc_memcpy(void *dest, const void *src, size_t n) __arm_streaming_compatible {
@@ -80,12 +105,12 @@ void *test_sc_memcpy(void *dest, const void *src, size_t n) __arm_streaming_comp
80105

81106
// CHECK-LABEL: @test_sc_memmove(
82107
// CHECK-NEXT: entry:
83-
// CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memmove(ptr noundef [[DEST:%.*]], ptr noundef [[SRC:%.*]], i64 noundef [[N:%.*]]) #[[ATTR5]]
108+
// CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memmove(ptr noundef [[DEST:%.*]], ptr noundef [[SRC:%.*]], i64 noundef [[N:%.*]]) #[[ATTR7]]
84109
// CHECK-NEXT: ret ptr [[CALL]]
85110
//
86111
// CPP-CHECK-LABEL: @_Z15test_sc_memmovePvPKvm(
87112
// CPP-CHECK-NEXT: entry:
88-
// CPP-CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memmove(ptr noundef [[DEST:%.*]], ptr noundef [[SRC:%.*]], i64 noundef [[N:%.*]]) #[[ATTR5]]
113+
// CPP-CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memmove(ptr noundef [[DEST:%.*]], ptr noundef [[SRC:%.*]], i64 noundef [[N:%.*]]) #[[ATTR7]]
89114
// CPP-CHECK-NEXT: ret ptr [[CALL]]
90115
//
91116
void *test_sc_memmove(void *dest, const void *src, size_t n) __arm_streaming_compatible {
@@ -94,12 +119,12 @@ void *test_sc_memmove(void *dest, const void *src, size_t n) __arm_streaming_com
94119

95120
// CHECK-LABEL: @test_sc_memset(
96121
// CHECK-NEXT: entry:
97-
// CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memset(ptr noundef [[S:%.*]], i32 noundef [[C:%.*]], i64 noundef [[N:%.*]]) #[[ATTR5]]
122+
// CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memset(ptr noundef [[S:%.*]], i32 noundef [[C:%.*]], i64 noundef [[N:%.*]]) #[[ATTR7]]
98123
// CHECK-NEXT: ret ptr [[CALL]]
99124
//
100125
// CPP-CHECK-LABEL: @_Z14test_sc_memsetPvim(
101126
// CPP-CHECK-NEXT: entry:
102-
// CPP-CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memset(ptr noundef [[S:%.*]], i32 noundef [[C:%.*]], i64 noundef [[N:%.*]]) #[[ATTR5]]
127+
// CPP-CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memset(ptr noundef [[S:%.*]], i32 noundef [[C:%.*]], i64 noundef [[N:%.*]]) #[[ATTR7]]
103128
// CPP-CHECK-NEXT: ret ptr [[CALL]]
104129
//
105130
void *test_sc_memset(void *s, int c, size_t n) __arm_streaming_compatible {
@@ -108,12 +133,12 @@ void *test_sc_memset(void *s, int c, size_t n) __arm_streaming_compatible {
108133

109134
// CHECK-LABEL: @test_sc_memchr(
110135
// CHECK-NEXT: entry:
111-
// CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memchr(ptr noundef [[S:%.*]], i32 noundef [[C:%.*]], i64 noundef [[N:%.*]]) #[[ATTR5]]
136+
// CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memchr(ptr noundef [[S:%.*]], i32 noundef [[C:%.*]], i64 noundef [[N:%.*]]) #[[ATTR7]]
112137
// CHECK-NEXT: ret ptr [[CALL]]
113138
//
114139
// CPP-CHECK-LABEL: @_Z14test_sc_memchrPvim(
115140
// CPP-CHECK-NEXT: entry:
116-
// CPP-CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memchr(ptr noundef [[S:%.*]], i32 noundef [[C:%.*]], i64 noundef [[N:%.*]]) #[[ATTR5]]
141+
// CPP-CHECK-NEXT: [[CALL:%.*]] = tail call ptr @__arm_sc_memchr(ptr noundef [[S:%.*]], i32 noundef [[C:%.*]], i64 noundef [[N:%.*]]) #[[ATTR7]]
117142
// CPP-CHECK-NEXT: ret ptr [[CALL]]
118143
//
119144
void *test_sc_memchr(void *s, int c, size_t n) __arm_streaming_compatible {

llvm/test/CodeGen/AArch64/sme-intrinsics-state.ll

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; RUN: llc -mtriple=aarch64-linux-gnu -mattr=+sme -verify-machineinstrs < %s | FileCheck %s
33

44

5-
define i1 @streaming_mode_st_compatible() #0 {
5+
define i1 @streaming_mode_streaming_compatible() #0 {
66
; CHECK-LABEL: streaming_mode_st_compatible:
77
; CHECK: // %bb.0:
88
; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
@@ -14,31 +14,5 @@ define i1 @streaming_mode_st_compatible() #0 {
1414
ret i1 %mode
1515
}
1616

17-
define i1 @streaming_mode_st_enabled() #1 {
18-
; CHECK-LABEL: streaming_mode_st_enabled:
19-
; CHECK: // %bb.0:
20-
; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
21-
; CHECK-NEXT: bl __arm_sme_state
22-
; CHECK-NEXT: and w0, w0, #0x1
23-
; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
24-
; CHECK-NEXT: ret
25-
%mode = tail call noundef i1 @llvm.aarch64.sme.in.streaming.mode()
26-
ret i1 %mode
27-
}
28-
29-
define i1 @streaming_mode_st_disabled() #2 {
30-
; CHECK-LABEL: streaming_mode_st_disabled:
31-
; CHECK: // %bb.0:
32-
; CHECK-NEXT: str x30, [sp, #-16]! // 8-byte Folded Spill
33-
; CHECK-NEXT: bl __arm_sme_state
34-
; CHECK-NEXT: and w0, w0, #0x1
35-
; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
36-
; CHECK-NEXT: ret
37-
%mode = tail call noundef i1 @llvm.aarch64.sme.in.streaming.mode()
38-
ret i1 %mode
39-
}
40-
4117

4218
attributes #0 = {nounwind memory(none) "aarch64_pstate_sm_compatible"}
43-
attributes #1 = {nounwind memory(none) "aarch64_pstate_sm_enabled"}
44-
attributes #2 = {nounwind memory(none)}

0 commit comments

Comments
 (0)