1 ; RUN: llc < %s -mtriple=i686-- -stackrealign -O2 | FileCheck %s
4 ; Check that register allocator is able to handle that
5 ; a-lot-of-fixed-and-reserved-registers case. We do that by
6 ; emmiting lea before 4 cmpxchg8b operands generators.
8 define void @foo_alloca(ptr %a, i32 %off, i32 %n) {
9 %dummy = alloca i32, i32 %n
10 %addr = getelementptr inbounds i64, ptr %a, i32 %off
12 %res = cmpxchg ptr %addr, i64 0, i64 1 monotonic monotonic
16 ; CHECK-LABEL: foo_alloca
17 ; CHECK: leal {{\(%e..,%e..,.*\)}}, [[REGISTER:%e.i]]
18 ; CHECK-NEXT: xorl %eax, %eax
19 ; CHECK-NEXT: xorl %edx, %edx
20 ; CHECK-NEXT: xorl %ecx, %ecx
21 ; CHECK-NEXT: movl $1, %ebx
22 ; CHECK-NEXT: lock cmpxchg8b ([[REGISTER]])
24 ; If we don't use index register in the address mode -
25 ; check that we did not generate the lea.
26 define void @foo_alloca_direct_address(ptr %addr, i32 %n) {
27 %dummy = alloca i32, i32 %n
29 %res = cmpxchg ptr %addr, i64 0, i64 1 monotonic monotonic
33 ; CHECK-LABEL: foo_alloca_direct_address
34 ; CHECK-NOT: leal {{\(%e.*\)}}, [[REGISTER:%e.i]]
35 ; CHECK: lock cmpxchg8b ([[REGISTER]])
37 ; We used to have a bug when combining:
38 ; - base pointer for stack frame (VLA + alignment)
39 ; - cmpxchg8b frameindex + index reg
41 declare void @escape(ptr)
43 define void @foo_alloca_index(i32 %i, i64 %val) {
45 %Counters = alloca [19 x i64], align 32
46 %vla = alloca i32, i32 %i
47 call void @escape(ptr %vla)
51 %p = getelementptr inbounds [19 x i64], ptr %Counters, i32 0, i32 %i
52 %t2 = cmpxchg volatile ptr %p, i64 %val, i64 %val seq_cst seq_cst
53 %t3 = extractvalue { i64, i1 } %t2, 0
54 %cmp.i = icmp eq i64 %val, %t3
55 br i1 %cmp.i, label %done, label %body
61 ; Check that we add a LEA
62 ; CHECK-LABEL: foo_alloca_index:
63 ; CHECK: leal {{[0-9]*\(%e..,%e..,8\), %e..}}
64 ; CHECK: lock cmpxchg8b ({{%e..}})
68 ; We used to have a bug when combining:
69 ; - base pointer for stack frame (VLA + alignment)
70 ; - cmpxchg8b global + index reg
72 @Counters = external dso_local global [19 x i64]
74 define void @foo_alloca_index_global(i32 %i, i64 %val) {
76 %aligner = alloca i32, align 32
77 call void @escape(ptr %aligner)
78 %vla = alloca i32, i32 %i
79 call void @escape(ptr %vla)
83 %p = getelementptr inbounds [19 x i64], ptr @Counters, i32 0, i32 %i
84 %t2 = cmpxchg volatile ptr %p, i64 %val, i64 %val seq_cst seq_cst
85 %t3 = extractvalue { i64, i1 } %t2, 0
86 %cmp.i = icmp eq i64 %val, %t3
87 br i1 %cmp.i, label %done, label %body
93 ; Check that we add a LEA
94 ; CHECK-LABEL: foo_alloca_index_global:
95 ; CHECK: leal {{Counters\(,%e..,8\), %e..}}
96 ; CHECK: lock cmpxchg8b ({{%e..}})