1 ; RUN: llc -mtriple=armv7-none-eabi -mattr=+neon < %s -o - | FileCheck %s
3 ; The following functions test the use case where an X constraint is used to
4 ; add a dependency between an assembly instruction (vmsr in this case) and
5 ; another instruction. In each function, we use a different type for the
6 ; X constraint argument.
8 ; We can something similar from the following C code:
9 ; double f1(double f, int pscr_value) {
10 ; asm volatile("vmsr fpscr,%0" : "=X" ((f)): "r" (pscr_value));
18 define arm_aapcs_vfpcc double @f1(double %f, i32 %pscr_value) {
20 %f.addr = alloca double, align 8
21 store double %f, ptr %f.addr, align 8
22 call void asm sideeffect "vmsr fpscr,$1", "=*X,r"(ptr elementtype(double) nonnull %f.addr, i32 %pscr_value) nounwind
23 %0 = load double, ptr %f.addr, align 8
24 %add = fadd double %0, %0
28 ; int f2(int f, int pscr_value) {
29 ; asm volatile("vmsr fpscr,%0" : "=X" ((f)): "r" (pscr_value));
36 define arm_aapcs_vfpcc i32 @f2(i32 %f, i32 %pscr_value) {
38 %f.addr = alloca i32, align 4
39 store i32 %f, ptr %f.addr, align 4
40 call void asm sideeffect "vmsr fpscr,$1", "=*X,r"(ptr elementtype(i32) nonnull %f.addr, i32 %pscr_value) nounwind
41 %0 = load i32, ptr %f.addr, align 4
47 ; int f3(int f, int pscr_value) {
48 ; asm volatile("vmsr fpscr,%0" : "=X" ((f)): "r" (pscr_value));
52 ; typedef signed char int8_t;
53 ; typedef __attribute__((neon_vector_type(8))) int8_t int8x8_t;
56 ; int8x8_t vector_res_int8x8;
58 ; asm volatile ("vmsr fpscr,%1" : "=X" ((vector_res_int8x8)) : "r" (fpscr));
59 ; return vector_res_int8x8 * vector_res_int8x8;
65 define arm_aapcs_vfpcc <8 x i8> @f3() {
67 %vector_res_int8x8 = alloca <8 x i8>, align 8
68 %0 = getelementptr inbounds <8 x i8>, ptr %vector_res_int8x8, i32 0, i32 0
69 call void asm sideeffect "vmsr fpscr,$1", "=*X,r"(ptr elementtype(<8 x i8>) nonnull %vector_res_int8x8, i32 undef) nounwind
70 %1 = load <8 x i8>, ptr %vector_res_int8x8, align 8
71 %mul = mul <8 x i8> %1, %1
75 ; We can emit integer constants.
76 ; We can get this from:
79 ; asm volatile ("add r0, r0, %0" : : "X" (x));
83 ; CHECK: add r0, r0, #2
86 tail call void asm sideeffect "add r0, r0, $0", "X"(i32 2)
90 ; We can emit function labels. This is equivalent to the following C code:
92 ; void (*x)(void) = &foo;
93 ; asm volatile ("bl %0" : : "X" (x));
99 tail call void asm sideeffect "bl $0", "X"(ptr nonnull @f4)
103 declare void @foo(...)
105 ; This tests the behavior of the X constraint when used on functions pointers,
106 ; or functions with a cast. In the first asm call we figure out that this
107 ; is a function pointer and emit the label. With opaque pointers, we also do
108 ; so in the second case.
114 define void @f6() nounwind {
116 tail call void asm sideeffect "bl $0", "X"(ptr @foo) nounwind
117 tail call void asm sideeffect "bl $0", "X"(ptr @f4) nounwind
121 ; The following IR can be generated from C code with a function like:
124 ; asm volatile ("bl %0" : : "X" (a));
129 ; Ideally this would give the block address of bb, but it requires us to see
130 ; through blockaddress, which we can't do at the moment. This might break some
131 ; existing use cases where a user would expect to get a block label and instead
132 ; gets the block address in a register. However, note that according to the
133 ; "no constraints" definition this behaviour is correct (although not very nice).
138 call void asm sideeffect "bl $0", "X"( ptr blockaddress(@f7, %bb) )
144 ; If we use a constraint "=*X", we should get a store back to *%x (in r0).
146 ; CHECK: str r{{.*}}, [r0]
147 define void @f8(ptr %x) {
149 tail call void asm sideeffect "add $0, r0, r0", "=*X"(ptr elementtype(i32) %x)