1 // RUN: %clang_cc1 -triple thumbv8.1m.main-none-none-eabi -target-feature +mve.fp -flax-vector-conversions=all -fdouble-square-bracket-attributes -Werror -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -triple thumbv8.1m.main-none-none-eabi -target-feature +mve.fp -flax-vector-conversions=all -fdouble-square-bracket-attributes -verify -fsyntax-only -DERROR_CHECK %s
4 typedef signed short int16_t;
5 typedef signed int int32_t;
6 typedef signed long long int64_t;
7 typedef unsigned short uint16_t;
8 typedef unsigned int uint32_t;
9 typedef unsigned long long uint64_t;
11 typedef __attribute__((neon_vector_type(8), __clang_arm_mve_strict_polymorphism
)) int16_t int16x8_t
;
12 typedef __attribute__((neon_vector_type(4), __clang_arm_mve_strict_polymorphism
)) int32_t int32x4_t
;
13 typedef __attribute__((neon_vector_type(2), __clang_arm_mve_strict_polymorphism
)) int64_t int64x2_t
;
14 typedef __attribute__((neon_vector_type(8), __clang_arm_mve_strict_polymorphism
)) uint16_t uint16x8_t
;
15 typedef __attribute__((neon_vector_type(4), __clang_arm_mve_strict_polymorphism
)) uint32_t uint32x4_t
;
16 typedef __attribute__((neon_vector_type(2), __clang_arm_mve_strict_polymorphism
)) uint64_t uint64x2_t
;
18 // Verify that we can use the [[]] spelling of the attribute.
19 // We intentionally use the same type alias name to check that both versions
20 // define the same type.
21 typedef int16_t [[clang::neon_vector_type(8), clang::__clang_arm_mve_strict_polymorphism
]] int16x8_t
;
23 // Verify that we can use the attribute outside of a typedef.
24 void test_param(int16_t [[clang::neon_vector_type(8), clang::__clang_arm_mve_strict_polymorphism
]] int16x8
);
26 __attribute__((overloadable
))
27 int overload(int16x8_t x
, int16_t y
); // expected-note {{candidate function}}
28 __attribute__((overloadable
))
29 int overload(int32x4_t x
, int32_t y
); // expected-note {{candidate function}}
30 __attribute__((overloadable
))
31 int overload(uint16x8_t x
, uint16_t y
); // expected-note {{candidate function}}
32 __attribute__((overloadable
))
33 int overload(uint32x4_t x
, uint32_t y
); // expected-note {{candidate function}}
45 // ----------------------------------------------------------------------
46 // Simple cases where the types are correctly matched
48 // CHECK-LABEL: @test_easy_s16(
49 // CHECK: call i32 @_Z8overload{{[a-zA-Z0-9_]+}}_int16
50 int test_easy_s16(void) { return overload(vs16
, s16
); }
52 // CHECK-LABEL: @test_easy_u16(
53 // CHECK: call i32 @_Z8overload{{[a-zA-Z0-9_]+}}_uint16
54 int test_easy_u16(void) { return overload(vu16
, u16
); }
56 // CHECK-LABEL: @test_easy_s32(
57 // CHECK: call i32 @_Z8overload{{[a-zA-Z0-9_]+}}_int32
58 int test_easy_s32(void) { return overload(vs32
, s32
); }
60 // CHECK-LABEL: @test_easy_u32(
61 // CHECK: call i32 @_Z8overload{{[a-zA-Z0-9_]+}}_uint32
62 int test_easy_u32(void) { return overload(vu32
, u32
); }
64 // ----------------------------------------------------------------------
65 // Do arithmetic on the scalar, and it may get promoted. We still expect the
66 // same overloads to be selected if that happens.
68 // CHECK-LABEL: @test_promote_s16(
69 // CHECK: call i32 @_Z8overload{{[a-zA-Z0-9_]+}}_int16
70 int test_promote_s16(void) { return overload(vs16
, s16
+ 1); }
72 // CHECK-LABEL: @test_promote_u16(
73 // CHECK: call i32 @_Z8overload{{[a-zA-Z0-9_]+}}_uint16
74 int test_promote_u16(void) { return overload(vu16
, u16
+ 1); }
76 // CHECK-LABEL: @test_promote_s32(
77 // CHECK: call i32 @_Z8overload{{[a-zA-Z0-9_]+}}_int32
78 int test_promote_s32(void) { return overload(vs32
, s32
+ 1); }
80 // CHECK-LABEL: @test_promote_u32(
81 // CHECK: call i32 @_Z8overload{{[a-zA-Z0-9_]+}}_uint32
82 int test_promote_u32(void) { return overload(vu32
, u32
+ 1); }
84 // ----------------------------------------------------------------------
85 // Write a simple integer literal without qualification, and expect
86 // the vector type to make it unambiguous which integer type you meant
89 // CHECK-LABEL: @test_literal_s16(
90 // CHECK: call i32 @_Z8overload{{[a-zA-Z0-9_]+}}_int16
91 int test_literal_s16(void) { return overload(vs16
, 1); }
93 // CHECK-LABEL: @test_literal_u16(
94 // CHECK: call i32 @_Z8overload{{[a-zA-Z0-9_]+}}_uint16
95 int test_literal_u16(void) { return overload(vu16
, 1); }
97 // CHECK-LABEL: @test_literal_s32(
98 // CHECK: call i32 @_Z8overload{{[a-zA-Z0-9_]+}}_int32
99 int test_literal_s32(void) { return overload(vs32
, 1); }
101 // CHECK-LABEL: @test_literal_u32(
102 // CHECK: call i32 @_Z8overload{{[a-zA-Z0-9_]+}}_uint32
103 int test_literal_u32(void) { return overload(vu32
, 1); }
105 // ----------------------------------------------------------------------
106 // All of those overload resolutions are supposed to be unambiguous even when
107 // lax vector conversion is enabled. Check here that a lax conversion in a
108 // different context still works.
109 int16x8_t
lax_conversion(void) { return vu32
; }
111 // ----------------------------------------------------------------------
112 // Use a vector type that there really _isn't_ any overload for, and
113 // make sure that we get a fatal compile error.
116 int expect_error(uint64x2_t v
) {
117 return overload(v
, 2); // expected-error {{no matching function for call to 'overload'}}
120 typedef __attribute__((__clang_arm_mve_strict_polymorphism
)) int i
; // expected-error {{'__clang_arm_mve_strict_polymorphism' attribute can only be applied to an MVE/NEON vector type}}
121 typedef __attribute__((__clang_arm_mve_strict_polymorphism
)) int f(void); // expected-error {{'__clang_arm_mve_strict_polymorphism' attribute can only be applied to an MVE/NEON vector type}}
122 typedef __attribute__((__clang_arm_mve_strict_polymorphism
)) struct { uint16x8_t v
; } s
; // expected-error {{'__clang_arm_mve_strict_polymorphism' attribute can only be applied to an MVE/NEON vector type}}