152 lines · plain
1; RUN: llc -mtriple=armv7-none-eabi -mattr=+neon < %s -o - | FileCheck %s2 3; The following functions test the use case where an X constraint is used to4; add a dependency between an assembly instruction (vmsr in this case) and5; another instruction. In each function, we use a different type for the6; X constraint argument.7;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));11; return f+f;12; }13 14; CHECK-LABEL: f115; CHECK: vmsr fpscr16; CHECK: vadd.f6417 18define arm_aapcs_vfpcc double @f1(double %f, i32 %pscr_value) {19entry:20 %f.addr = alloca double, align 821 store double %f, ptr %f.addr, align 822 call void asm sideeffect "vmsr fpscr,$1", "=*X,r"(ptr elementtype(double) nonnull %f.addr, i32 %pscr_value) nounwind23 %0 = load double, ptr %f.addr, align 824 %add = fadd double %0, %025 ret double %add26}27 28; int f2(int f, int pscr_value) {29; asm volatile("vmsr fpscr,%0" : "=X" ((f)): "r" (pscr_value));30; return f+f;31; }32 33; CHECK-LABEL: f234; CHECK: vmsr fpscr35; CHECK: mul36define arm_aapcs_vfpcc i32 @f2(i32 %f, i32 %pscr_value) {37entry:38 %f.addr = alloca i32, align 439 store i32 %f, ptr %f.addr, align 440 call void asm sideeffect "vmsr fpscr,$1", "=*X,r"(ptr elementtype(i32) nonnull %f.addr, i32 %pscr_value) nounwind41 %0 = load i32, ptr %f.addr, align 442 %mul = mul i32 %0, %043 ret i32 %mul44}45 46 47; int f3(int f, int pscr_value) {48; asm volatile("vmsr fpscr,%0" : "=X" ((f)): "r" (pscr_value));49; return f+f;50; }51 52; typedef signed char int8_t;53; typedef __attribute__((neon_vector_type(8))) int8_t int8x8_t;54; void f3 (void)55; {56; int8x8_t vector_res_int8x8;57; unsigned int fpscr;58; asm volatile ("vmsr fpscr,%1" : "=X" ((vector_res_int8x8)) : "r" (fpscr));59; return vector_res_int8x8 * vector_res_int8x8;60; }61 62; CHECK-LABEL: f363; CHECK: vmsr fpscr64; CHECK: vmul.i865define arm_aapcs_vfpcc <8 x i8> @f3() {66entry:67 %vector_res_int8x8 = alloca <8 x i8>, align 868 %0 = getelementptr inbounds <8 x i8>, ptr %vector_res_int8x8, i32 0, i32 069 call void asm sideeffect "vmsr fpscr,$1", "=*X,r"(ptr elementtype(<8 x i8>) nonnull %vector_res_int8x8, i32 undef) nounwind70 %1 = load <8 x i8>, ptr %vector_res_int8x8, align 871 %mul = mul <8 x i8> %1, %172 ret <8 x i8> %mul73}74 75; We can emit integer constants.76; We can get this from:77; void f() {78; int x = 2;79; asm volatile ("add r0, r0, %0" : : "X" (x));80; }81;82; CHECK-LABEL: f483; CHECK: add r0, r0, #284define void @f4() {85entry:86 tail call void asm sideeffect "add r0, r0, $0", "X"(i32 2)87 ret void88}89 90; We can emit function labels. This is equivalent to the following C code:91; void f(void) {92; void (*x)(void) = &foo;93; asm volatile ("bl %0" : : "X" (x));94; }95; CHECK-LABEL: f596; CHECK: bl f497define void @f5() {98entry:99 tail call void asm sideeffect "bl $0", "X"(ptr nonnull @f4)100 ret void101}102 103declare void @foo(...)104 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 this107; is a function pointer and emit the label. With opaque pointers, we also do108; so in the second case.109 110; CHECK-LABEL: f6111; CHECK: bl foo112; CHECK: bl f4113 114define void @f6() nounwind {115entry:116 tail call void asm sideeffect "bl $0", "X"(ptr @foo) nounwind117 tail call void asm sideeffect "bl $0", "X"(ptr @f4) nounwind118 ret void119}120 121; The following IR can be generated from C code with a function like:122; void a() {123; void* a = &&A;124; asm volatile ("bl %0" : : "X" (a));125; A:126; return;127; }128;129; Ideally this would give the block address of bb, but it requires us to see130; through blockaddress, which we can't do at the moment. This might break some131; existing use cases where a user would expect to get a block label and instead132; gets the block address in a register. However, note that according to the133; "no constraints" definition this behaviour is correct (although not very nice).134 135; CHECK-LABEL: f7136; CHECK: bl137define void @f7() {138 call void asm sideeffect "bl $0", "X"( ptr blockaddress(@f7, %bb) )139 br label %bb140bb:141 ret void142}143 144; If we use a constraint "=*X", we should get a store back to *%x (in r0).145; CHECK-LABEL: f8146; CHECK: str r{{.*}}, [r0]147define void @f8(ptr %x) {148entry:149 tail call void asm sideeffect "add $0, r0, r0", "=*X"(ptr elementtype(i32) %x)150 ret void151}152