xref: /llvm-project/llvm/test/CodeGen/X86/cmpxchg8b_alloca_regalloc_handling.ll (revision 2f448bf509432c1a19ec46ab8cbc7353c03c6280)
1; RUN: llc < %s -mtriple=i686-- -stackrealign -O2 | FileCheck %s
2; PR28755
3
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.
7
8define void @foo_alloca(ptr %a, i32 %off, i32 %n) {
9  %dummy = alloca i32, i32 %n
10  %addr = getelementptr inbounds i64, ptr %a, i32 %off
11
12  %res = cmpxchg ptr %addr, i64 0, i64 1 monotonic monotonic
13  ret void
14}
15
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]])
23
24; If we don't use index register in the address mode -
25; check that we did not generate the lea.
26define void @foo_alloca_direct_address(ptr %addr, i32 %n) {
27  %dummy = alloca i32, i32 %n
28
29  %res = cmpxchg ptr %addr, i64 0, i64 1 monotonic monotonic
30  ret void
31}
32
33; CHECK-LABEL: foo_alloca_direct_address
34; CHECK-NOT: leal    {{\(%e.*\)}}, [[REGISTER:%e.i]]
35; CHECK: lock            cmpxchg8b       ([[REGISTER]])
36
37; We used to have a bug when combining:
38; - base pointer for stack frame (VLA + alignment)
39; - cmpxchg8b frameindex + index reg
40
41declare void @escape(ptr)
42
43define void @foo_alloca_index(i32 %i, i64 %val) {
44entry:
45  %Counters = alloca [19 x i64], align 32
46  %vla = alloca i32, i32 %i
47  call void @escape(ptr %vla)
48  br label %body
49
50body:
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
56
57done:
58  ret void
59}
60
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..}})
65
66
67
68; We used to have a bug when combining:
69; - base pointer for stack frame (VLA + alignment)
70; - cmpxchg8b global + index reg
71
72@Counters = external dso_local global [19 x i64]
73
74define void @foo_alloca_index_global(i32 %i, i64 %val) {
75entry:
76  %aligner = alloca i32, align 32
77  call void @escape(ptr %aligner)
78  %vla = alloca i32, i32 %i
79  call void @escape(ptr %vla)
80  br label %body
81
82body:
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
88
89done:
90  ret void
91}
92
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..}})
97