1 // RUN: %clang_cc1 %s -triple x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
2 // Exercise various use cases for local asm "register variables".
3
foo()4 int foo() {
5 // CHECK-LABEL: define i32 @foo()
6 // CHECK: [[A:%[a-zA-Z0-9]+]] = alloca i32
7
8 register int a asm("rsi")=5;
9 // CHECK: store i32 5, i32* [[A]]
10
11 asm volatile("; %0 This asm defines rsi" : "=r"(a));
12 // CHECK: [[Z:%[a-zA-Z0-9]+]] = call i32 asm sideeffect "; $0 This asm defines rsi", "={rsi},~{dirflag},~{fpsr},~{flags}"()
13 // CHECK: store i32 [[Z]], i32* [[A]]
14
15 a = 42;
16 // CHECK: store i32 42, i32* [[A]]
17
18 asm volatile("; %0 This asm uses rsi" : : "r"(a));
19 // CHECK: [[TMP:%[a-zA-Z0-9]+]] = load i32, i32* [[A]]
20 // CHECK: call void asm sideeffect "; $0 This asm uses rsi", "{rsi},~{dirflag},~{fpsr},~{flags}"(i32 [[TMP]])
21
22 return a;
23 // CHECK: [[TMP1:%[a-zA-Z0-9]+]] = load i32, i32* [[A]]
24 // CHECK: ret i32 [[TMP1]]
25 }
26
earlyclobber()27 int earlyclobber() {
28 // CHECK-LABEL: define i32 @earlyclobber()
29 // CHECK: [[A:%[a-zA-Z0-9]+]] = alloca i32
30
31 register int a asm("rsi")=5;
32 // CHECK: store i32 5, i32* [[A]]
33
34 asm volatile("; %0 This asm defines rsi" : "=&r"(a));
35 // CHECK: [[Z:%[a-zA-Z0-9]+]] = call i32 asm sideeffect "; $0 This asm defines rsi", "=&{rsi},~{dirflag},~{fpsr},~{flags}"()
36 // CHECK: store i32 [[Z]], i32* [[A]]
37
38 a = 42;
39 // CHECK: store i32 42, i32* [[A]]
40
41 asm volatile("; %0 This asm uses rsi" : : "r"(a));
42 // CHECK: [[TMP:%[a-zA-Z0-9]+]] = load i32, i32* [[A]]
43 // CHECK: call void asm sideeffect "; $0 This asm uses rsi", "{rsi},~{dirflag},~{fpsr},~{flags}"(i32 [[TMP]])
44
45 return a;
46 // CHECK: [[TMP1:%[a-zA-Z0-9]+]] = load i32, i32* [[A]]
47 // CHECK: ret i32 [[TMP1]]
48 }
49