NAKAMURA Takumi | cc59e91 | 2012-09-27 14:55:08 +0000 | [diff] [blame] | 1 | // REQUIRES: x86-64-registered-target |
Chad Rosier | 82573e3 | 2012-10-23 23:32:21 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 %s -triple i386-apple-darwin10 -O0 -fms-extensions -fenable-experimental-ms-inline-asm -w -emit-llvm -o - | FileCheck %s |
Chad Rosier | 25bc47e | 2012-10-19 20:38:09 +0000 | [diff] [blame] | 3 | |
Chad Rosier | b64f310 | 2012-08-08 20:37:31 +0000 | [diff] [blame] | 4 | void t1() { |
| 5 | // CHECK: @t1 |
Chad Rosier | fcf75a3 | 2012-09-05 19:01:07 +0000 | [diff] [blame] | 6 | // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | b64f310 | 2012-08-08 20:37:31 +0000 | [diff] [blame] | 7 | // CHECK: ret void |
| 8 | __asm {} |
| 9 | } |
Chad Rosier | 265f538 | 2012-08-13 20:32:07 +0000 | [diff] [blame] | 10 | |
| 11 | void t2() { |
| 12 | // CHECK: @t2 |
Chad Rosier | fcf75a3 | 2012-09-05 19:01:07 +0000 | [diff] [blame] | 13 | // CHECK: call void asm sideeffect inteldialect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind |
| 14 | // CHECK: call void asm sideeffect inteldialect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind |
| 15 | // CHECK: call void asm sideeffect inteldialect "nop", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 265f538 | 2012-08-13 20:32:07 +0000 | [diff] [blame] | 16 | // CHECK: ret void |
| 17 | __asm nop |
| 18 | __asm nop |
| 19 | __asm nop |
| 20 | } |
| 21 | |
| 22 | void t3() { |
| 23 | // CHECK: @t3 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 24 | // CHECK: call void asm sideeffect inteldialect "nop\0A\09nop\0A\09nop", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 265f538 | 2012-08-13 20:32:07 +0000 | [diff] [blame] | 25 | // CHECK: ret void |
| 26 | __asm nop __asm nop __asm nop |
| 27 | } |
| 28 | |
| 29 | void t4(void) { |
| 30 | // CHECK: @t4 |
Chad Rosier | fcf75a3 | 2012-09-05 19:01:07 +0000 | [diff] [blame] | 31 | // CHECK: call void asm sideeffect inteldialect "mov ebx, eax", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind |
| 32 | // CHECK: call void asm sideeffect inteldialect "mov ecx, ebx", "~{ecx},~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 265f538 | 2012-08-13 20:32:07 +0000 | [diff] [blame] | 33 | // CHECK: ret void |
| 34 | __asm mov ebx, eax |
| 35 | __asm mov ecx, ebx |
| 36 | } |
| 37 | |
| 38 | void t5(void) { |
| 39 | // CHECK: @t5 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 40 | // CHECK: call void asm sideeffect inteldialect "mov ebx, eax\0A\09mov ecx, ebx", "~{ebx},~{ecx},~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 265f538 | 2012-08-13 20:32:07 +0000 | [diff] [blame] | 41 | // CHECK: ret void |
| 42 | __asm mov ebx, eax __asm mov ecx, ebx |
| 43 | } |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 44 | |
| 45 | void t6(void) { |
| 46 | __asm int 0x2c |
| 47 | // CHECK: t6 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 48 | // CHECK: call void asm sideeffect inteldialect "int $$0x2c", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 51 | void t7() { |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 52 | __asm { |
| 53 | int 0x2c ; } asm comments are fun! }{ |
| 54 | } |
| 55 | __asm {} |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 56 | // CHECK: t7 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 57 | // CHECK: call void asm sideeffect inteldialect "int $$0x2c", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | fcf75a3 | 2012-09-05 19:01:07 +0000 | [diff] [blame] | 58 | // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 59 | } |
Chad Rosier | ac9289d | 2012-10-02 20:55:30 +0000 | [diff] [blame] | 60 | |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 61 | int t8() { |
Chad Rosier | d9b56ed | 2012-10-15 19:56:10 +0000 | [diff] [blame] | 62 | __asm int 4 ; } comments for single-line asm |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 63 | __asm {} |
| 64 | __asm int 4 |
| 65 | return 10; |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 66 | // CHECK: t8 |
Chad Rosier | d9b56ed | 2012-10-15 19:56:10 +0000 | [diff] [blame] | 67 | // CHECK: call void asm sideeffect inteldialect "int $$4", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | fcf75a3 | 2012-09-05 19:01:07 +0000 | [diff] [blame] | 68 | // CHECK: call void asm sideeffect inteldialect "", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 69 | // CHECK: call void asm sideeffect inteldialect "int $$4", "~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 70 | // CHECK: ret i32 10 |
| 71 | } |
Chad Rosier | ac9289d | 2012-10-02 20:55:30 +0000 | [diff] [blame] | 72 | |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 73 | void t9() { |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 74 | __asm { |
| 75 | push ebx |
| 76 | mov ebx, 0x07 |
| 77 | pop ebx |
| 78 | } |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 79 | // CHECK: t9 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 80 | // CHECK: call void asm sideeffect inteldialect "push ebx\0A\09mov ebx, $$0x07\0A\09pop ebx", "~{ebx},~{dirflag},~{fpsr},~{flags}"() nounwind |
Chad Rosier | 27ef16b | 2012-08-14 23:48:41 +0000 | [diff] [blame] | 81 | } |
Chad Rosier | f64c118 | 2012-08-16 17:10:59 +0000 | [diff] [blame] | 82 | |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 83 | unsigned t10(void) { |
Chad Rosier | f64c118 | 2012-08-16 17:10:59 +0000 | [diff] [blame] | 84 | unsigned i = 1, j; |
| 85 | __asm { |
| 86 | mov eax, i |
| 87 | mov j, eax |
| 88 | } |
| 89 | return j; |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 90 | // CHECK: t10 |
Chad Rosier | f64c118 | 2012-08-16 17:10:59 +0000 | [diff] [blame] | 91 | // CHECK: [[I:%[a-zA-Z0-9]+]] = alloca i32, align 4 |
| 92 | // CHECK: [[J:%[a-zA-Z0-9]+]] = alloca i32, align 4 |
| 93 | // CHECK: store i32 1, i32* [[I]], align 4 |
Chad Rosier | 362b18c | 2012-10-19 20:57:37 +0000 | [diff] [blame] | 94 | // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $1\0A\09mov dword ptr $0, eax", "=*m,*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32* %{{.*}}) nounwind |
Chad Rosier | f64c118 | 2012-08-16 17:10:59 +0000 | [diff] [blame] | 95 | // CHECK: [[RET:%[a-zA-Z0-9]+]] = load i32* [[J]], align 4 |
| 96 | // CHECK: ret i32 [[RET]] |
| 97 | } |
Chad Rosier | 700ce64 | 2012-08-16 22:25:38 +0000 | [diff] [blame] | 98 | |
Chad Rosier | 7fcde17 | 2012-08-21 17:01:26 +0000 | [diff] [blame] | 99 | void t11(void) { |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 100 | __asm mov eax, 1 |
Chad Rosier | fba3fb9 | 2012-10-12 21:37:00 +0000 | [diff] [blame] | 101 | // CHECK: t11 |
Chad Rosier | 4de9716 | 2012-09-11 00:51:28 +0000 | [diff] [blame] | 102 | // CHECK: call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind |
| 103 | } |
Chad Rosier | 7f9678b | 2012-09-12 18:14:25 +0000 | [diff] [blame] | 104 | |
Chad Rosier | fba3fb9 | 2012-10-12 21:37:00 +0000 | [diff] [blame] | 105 | unsigned t12(void) { |
Chad Rosier | b55e602 | 2012-09-13 00:06:55 +0000 | [diff] [blame] | 106 | unsigned i = 1, j, l = 1, m; |
| 107 | __asm { |
| 108 | mov eax, i |
| 109 | mov j, eax |
| 110 | mov eax, l |
| 111 | mov m, eax |
| 112 | } |
| 113 | return j + m; |
Chad Rosier | fba3fb9 | 2012-10-12 21:37:00 +0000 | [diff] [blame] | 114 | // CHECK: t12 |
Chad Rosier | 362b18c | 2012-10-19 20:57:37 +0000 | [diff] [blame] | 115 | // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $2\0A\09mov dword ptr $0, eax\0A\09mov eax, dword ptr $3\0A\09mov dword ptr $1, eax", "=*m,=*m,*m,*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}, i32* %{{.*}}, i32* %{{.*}}, i32* %{{.*}}) nounwind |
| 116 | } |
| 117 | |
| 118 | void t13() { |
| 119 | char i = 1; |
| 120 | short j = 2; |
| 121 | __asm movzx eax, i |
| 122 | __asm movzx eax, j |
| 123 | // CHECK: t13 |
| 124 | // CHECK: call void asm sideeffect inteldialect "movzx eax, byte ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i8* %{{.*}}) nounwind |
| 125 | // CHECK: call void asm sideeffect inteldialect "movzx eax, word ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i16* %{{.*}}) nounwind |
Chad Rosier | b55e602 | 2012-09-13 00:06:55 +0000 | [diff] [blame] | 126 | } |
Chad Rosier | b0850b3 | 2012-10-19 23:16:17 +0000 | [diff] [blame] | 127 | |
| 128 | void t14() { |
| 129 | unsigned i = 1, j = 2; |
| 130 | __asm { |
| 131 | .if 1 |
| 132 | mov eax, i |
| 133 | .else |
| 134 | mov ebx, j |
| 135 | .endif |
| 136 | } |
| 137 | // CHECK: t14 |
Eli Friedman | 293e2eb | 2012-10-22 20:50:45 +0000 | [diff] [blame] | 138 | // CHECK: call void asm sideeffect inteldialect ".if 1\0A\09mov eax, dword ptr $0\0A\09.else\0A\09mov ebx, j\0A\09.endif", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}) nounwind |
Chad Rosier | b0850b3 | 2012-10-19 23:16:17 +0000 | [diff] [blame] | 139 | } |
Chad Rosier | 5a12aca | 2012-10-22 19:43:17 +0000 | [diff] [blame] | 140 | |
| 141 | void t15() { |
| 142 | int var = 10; |
| 143 | __asm mov eax, var ; eax = 10 |
| 144 | __asm mov eax, offset var ; eax = address of myvar |
| 145 | // CHECK: t15 |
| 146 | // CHECK: call void asm sideeffect inteldialect "mov eax, dword ptr $0", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}) nounwind |
Chad Rosier | 4d5dd7c | 2012-10-23 17:44:40 +0000 | [diff] [blame] | 147 | // CHECK: call void asm sideeffect inteldialect "mov eax, $0", "r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}) nounwind |
Chad Rosier | 5a12aca | 2012-10-22 19:43:17 +0000 | [diff] [blame] | 148 | } |
Chad Rosier | 4224255 | 2012-10-24 17:23:06 +0000 | [diff] [blame] | 149 | |
| 150 | void t16() { |
| 151 | int var = 10; |
| 152 | __asm mov [eax], offset var |
| 153 | // CHECK: t16 |
| 154 | // CHECK: call void asm sideeffect inteldialect "mov [eax], $0", "r,~{dirflag},~{fpsr},~{flags}"(i32* %{{.*}}) nounwind |
| 155 | } |
Chad Rosier | 1bed9b7 | 2012-10-24 17:48:01 +0000 | [diff] [blame] | 156 | |
| 157 | void t17() { |
| 158 | __asm _emit 0x4A |
| 159 | __asm _emit 0x43 |
| 160 | __asm _emit 0x4B |
| 161 | // CHECK: t17 |
| 162 | // CHECK: call void asm sideeffect inteldialect ".byte 0x4A", "~{dirflag},~{fpsr},~{flags}"() nounwind |
| 163 | // CHECK: call void asm sideeffect inteldialect ".byte 0x43", "~{dirflag},~{fpsr},~{flags}"() nounwind |
| 164 | // CHECK: call void asm sideeffect inteldialect ".byte 0x4B", "~{dirflag},~{fpsr},~{flags}"() nounwind |
| 165 | } |
Chad Rosier | f742727 | 2012-10-24 22:22:12 +0000 | [diff] [blame] | 166 | |
| 167 | struct t18_type { int a, b; }; |
| 168 | |
| 169 | int t18() { |
| 170 | struct t18_type foo; |
| 171 | foo.a = 1; |
| 172 | foo.b = 2; |
| 173 | __asm { |
| 174 | lea ebx, foo |
| 175 | mov eax, [ebx].0 |
| 176 | mov [ebx].4, ecx |
| 177 | } |
| 178 | return foo.b; |
| 179 | // CHECK: t18 |
| 180 | // CHECK: call void asm sideeffect inteldialect "lea ebx, foo\0A\09mov eax, [ebx].0\0A\09mov [ebx].4, ecx", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind |
| 181 | } |
Chad Rosier | d2e7d20 | 2012-10-25 21:52:03 +0000 | [diff] [blame] | 182 | |
| 183 | int t19() { |
| 184 | struct t18_type foo; |
| 185 | foo.a = 1; |
| 186 | foo.b = 2; |
| 187 | __asm { |
| 188 | lea ebx, foo |
| 189 | mov eax, [ebx].foo.a |
| 190 | mov [ebx].foo.b, ecx |
| 191 | } |
| 192 | return foo.b; |
| 193 | // CHECK: t19 |
| 194 | // CHECK: call void asm sideeffect inteldialect "lea ebx, foo\0A\09mov eax, [ebx].0\0A\09mov [ebx].4, ecx", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind |
| 195 | } |
Chad Rosier | da5c3b7 | 2012-10-26 18:04:45 +0000 | [diff] [blame^] | 196 | |
| 197 | void t20() { |
| 198 | int foo; |
| 199 | __asm mov eax, TYPE foo |
| 200 | // CHECK: t20 |
| 201 | // CHECK: call void asm sideeffect inteldialect "mov eax, $$4", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind |
| 202 | } |