xref: /llvm-project/llvm/test/CodeGen/X86/StackColoring-use-between-allocas.mir (revision e45523cd218f3360a14757c33fb9466bdb492380)
1# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2# RUN: llc -run-pass=stack-coloring %s -o - | FileCheck %s
3
4## %tmpcast is between 2 allocas. %ref.tmp will replaced by %tmp. Make sure
5## that we reorder %tmp to be before the use in %tmpcast.
6
7# CHECK: %a = alloca %struct.e, align 1
8# CHECK: %tmp = alloca %"struct.e::f", align 8
9# CHECK: %ref.tmp = alloca { <2 x float>, <2 x float> }, align 8
10# CHECK: %b = alloca %struct.j, align 4
11
12--- |
13  source_filename = "<stdin>"
14  target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
15  target triple = "x86_64-apple-macosx10.15.0"
16
17  %class.d = type { [4 x float] }
18  %struct.e = type { i8 }
19  %struct.j = type { i32 }
20  %"struct.e::f" = type { [4 x ptr] }
21
22  @i = local_unnamed_addr global %class.d zeroinitializer, align 8
23
24  ; Function Attrs: ssp uwtable
25  define void @_Z1gv() local_unnamed_addr #0 {
26  entry:
27    %a = alloca %struct.e, align 1
28    %ref.tmp = alloca { <2 x float>, <2 x float> }, align 8
29    %b = alloca %struct.j, align 4
30    %tmp = alloca %"struct.e::f", align 8
31    call void @llvm.lifetime.start.p0(i64 1, ptr nonnull %a) #3
32    call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %ref.tmp) #3
33    %agg.tmp.sroa.0.0.copyload = load <2 x float>, ptr @i, align 8, !tbaa.struct !3
34    %agg.tmp.sroa.2.0.copyload = load <2 x float>, ptr getelementptr inbounds (%class.d, ptr @i, i64 0, i32 0, i64 2), align 8, !tbaa.struct !3
35    %call = tail call { <2 x float>, <2 x float> } @_Zng1d(<2 x float> %agg.tmp.sroa.0.0.copyload, <2 x float> %agg.tmp.sroa.2.0.copyload)
36    %0 = extractvalue { <2 x float>, <2 x float> } %call, 0
37    store <2 x float> %0, ptr %ref.tmp, align 8
38    %1 = getelementptr inbounds { <2 x float>, <2 x float> }, ptr %ref.tmp, i64 0, i32 1
39    %2 = extractvalue { <2 x float>, <2 x float> } %call, 1
40    store <2 x float> %2, ptr %1, align 8
41    call void @_ZN1e1hERK1d(ptr nonnull %a, ptr nonnull dereferenceable(16) %ref.tmp)
42    call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %ref.tmp) #3
43    call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %b) #3
44    call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %tmp) #3
45    call void @_ZN1j1kEv(ptr nonnull sret(%"struct.e::f") align 8 %tmp, ptr nonnull %b)
46    call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %tmp) #3
47    call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %b) #3
48    call void @llvm.lifetime.end.p0(i64 1, ptr nonnull %a) #3
49    ret void
50  }
51
52  ; Function Attrs: argmemonly nounwind willreturn
53  declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
54
55  declare void @_ZN1e1hERK1d(ptr, ptr dereferenceable(16)) local_unnamed_addr #2
56
57  declare { <2 x float>, <2 x float> } @_Zng1d(<2 x float>, <2 x float>) local_unnamed_addr #2
58
59  ; Function Attrs: argmemonly nounwind willreturn
60  declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
61
62  declare void @_ZN1j1kEv(ptr sret(%"struct.e::f") align 8, ptr) local_unnamed_addr #2
63
64  ; Function Attrs: nounwind
65  declare void @llvm.stackprotector(ptr, ptr) #3
66
67  attributes #0 = { ssp uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="64" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
68  attributes #1 = { argmemonly nounwind willreturn }
69  attributes #2 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
70  attributes #3 = { nounwind }
71
72  !llvm.module.flags = !{!0, !1}
73  !llvm.ident = !{!2}
74
75  !0 = !{i32 1, !"wchar_size", i32 4}
76  !1 = !{i32 7, !"PIC Level", i32 2}
77  !2 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 82093e8fb7d65486ff450d33bf386aabd0d194f7)"}
78  !3 = !{i64 0, i64 16, !4}
79  !4 = !{!5, !5, i64 0}
80  !5 = !{!"omnipotent char", !6, i64 0}
81  !6 = !{!"Simple C++ TBAA"}
82
83...
84---
85name:            _Z1gv
86alignment:       16
87exposesReturnsTwice: false
88legalized:       false
89regBankSelected: false
90selected:        false
91failedISel:      false
92tracksRegLiveness: true
93hasWinCFI:       false
94registers:
95  - { id: 0, class: vr128, preferred-register: '' }
96  - { id: 1, class: vr128, preferred-register: '' }
97  - { id: 2, class: vr128, preferred-register: '' }
98  - { id: 3, class: vr128, preferred-register: '' }
99  - { id: 4, class: gr64, preferred-register: '' }
100  - { id: 5, class: gr64, preferred-register: '' }
101  - { id: 6, class: gr64, preferred-register: '' }
102  - { id: 7, class: gr64, preferred-register: '' }
103liveins:         []
104frameInfo:
105  isFrameAddressTaken: false
106  isReturnAddressTaken: false
107  hasStackMap:     false
108  hasPatchPoint:   false
109  stackSize:       0
110  offsetAdjustment: 0
111  maxAlignment:    8
112  adjustsStack:    false
113  hasCalls:        true
114  stackProtector:  ''
115  maxCallFrameSize: 4294967295
116  cvBytesOfCalleeSavedRegisters: 0
117  hasOpaqueSPAdjustment: false
118  hasVAStart:      false
119  hasMustTailInVarArgFunc: false
120  localFrameSize:  0
121  savePoint:       ''
122  restorePoint:    ''
123fixedStack:      []
124stack:
125  - { id: 0, name: a, type: default, offset: 0, size: 1, alignment: 8,
126      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
127      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
128  - { id: 1, name: ref.tmp, type: default, offset: 0, size: 16, alignment: 8,
129      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
130      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
131  - { id: 2, name: b, type: default, offset: 0, size: 4, alignment: 8,
132      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
133      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
134  - { id: 3, name: tmp, type: default, offset: 0, size: 32, alignment: 8,
135      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
136      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
137callSites:       []
138constants:       []
139machineFunctionInfo: {}
140body:             |
141  bb.0.entry:
142    ; CHECK-LABEL: name: _Z1gv
143    ; CHECK: [[MOVSDrm:%[0-9]+]]:vr128 = MOVSDrm $rip, 1, $noreg, @i, $noreg :: (dereferenceable load (s64) from @i)
144    ; CHECK-NEXT: [[MOVSDrm1:%[0-9]+]]:vr128 = MOVSDrm $rip, 1, $noreg, @i + 8, $noreg :: (dereferenceable load (s64) from `ptr getelementptr inbounds (%class.d, ptr @i, i64 0, i32 0, i64 2)`)
145    ; CHECK-NEXT: ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
146    ; CHECK-NEXT: $xmm0 = COPY [[MOVSDrm]]
147    ; CHECK-NEXT: $xmm1 = COPY [[MOVSDrm1]]
148    ; CHECK-NEXT: CALL64pcrel32 @_Zng1d, csr_64, implicit $rsp, implicit $ssp, implicit $xmm0, implicit $xmm1, implicit-def $rsp, implicit-def $ssp, implicit-def $xmm0, implicit-def $xmm1
149    ; CHECK-NEXT: ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
150    ; CHECK-NEXT: [[COPY:%[0-9]+]]:vr128 = COPY $xmm0
151    ; CHECK-NEXT: [[COPY1:%[0-9]+]]:vr128 = COPY $xmm1
152    ; CHECK-NEXT: MOVLPDmr %stack.3.tmp, 1, $noreg, 0, $noreg, [[COPY]] :: (store (s64) into %ir.tmp)
153    ; CHECK-NEXT: MOVLPDmr %stack.3.tmp, 1, $noreg, 8, $noreg, [[COPY1]] :: (store (s64) into %ir.1)
154    ; CHECK-NEXT: ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
155    ; CHECK-NEXT: [[LEA64r:%[0-9]+]]:gr64 = LEA64r %stack.0.a, 1, $noreg, 0, $noreg
156    ; CHECK-NEXT: [[LEA64r1:%[0-9]+]]:gr64 = LEA64r %stack.3.tmp, 1, $noreg, 0, $noreg
157    ; CHECK-NEXT: $rdi = COPY [[LEA64r]]
158    ; CHECK-NEXT: $rsi = COPY [[LEA64r1]]
159    ; CHECK-NEXT: CALL64pcrel32 @_ZN1e1hERK1d, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit $rsi, implicit-def $rsp, implicit-def $ssp
160    ; CHECK-NEXT: ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
161    ; CHECK-NEXT: ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
162    ; CHECK-NEXT: [[LEA64r2:%[0-9]+]]:gr64 = LEA64r %stack.3.tmp, 1, $noreg, 0, $noreg
163    ; CHECK-NEXT: [[LEA64r3:%[0-9]+]]:gr64 = LEA64r %stack.2.b, 1, $noreg, 0, $noreg
164    ; CHECK-NEXT: $rdi = COPY [[LEA64r2]]
165    ; CHECK-NEXT: $rsi = COPY [[LEA64r3]]
166    ; CHECK-NEXT: CALL64pcrel32 @_ZN1j1kEv, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit $rsi, implicit-def $rsp, implicit-def $ssp
167    ; CHECK-NEXT: ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
168    ; CHECK-NEXT: RET 0
169    LIFETIME_START %stack.0.a
170    LIFETIME_START %stack.1.ref.tmp
171    %0:vr128 = MOVSDrm $rip, 1, $noreg, @i, $noreg :: (dereferenceable load (s64) from @i)
172    %1:vr128 = MOVSDrm $rip, 1, $noreg, @i + 8, $noreg :: (dereferenceable load (s64) from `ptr getelementptr inbounds (%class.d, ptr @i, i64 0, i32 0, i64 2)`)
173    ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
174    $xmm0 = COPY %0
175    $xmm1 = COPY %1
176    CALL64pcrel32 @_Zng1d, csr_64, implicit $rsp, implicit $ssp, implicit $xmm0, implicit $xmm1, implicit-def $rsp, implicit-def $ssp, implicit-def $xmm0, implicit-def $xmm1
177    ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
178    %2:vr128 = COPY $xmm0
179    %3:vr128 = COPY $xmm1
180    MOVLPDmr %stack.1.ref.tmp, 1, $noreg, 0, $noreg, %2 :: (store (s64) into %ir.ref.tmp)
181    MOVLPDmr %stack.1.ref.tmp, 1, $noreg, 8, $noreg, %3 :: (store (s64) into %ir.1)
182    ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
183    %4:gr64 = LEA64r %stack.0.a, 1, $noreg, 0, $noreg
184    %5:gr64 = LEA64r %stack.1.ref.tmp, 1, $noreg, 0, $noreg
185    $rdi = COPY %4
186    $rsi = COPY %5
187    CALL64pcrel32 @_ZN1e1hERK1d, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit $rsi, implicit-def $rsp, implicit-def $ssp
188    ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
189    LIFETIME_END %stack.1.ref.tmp
190    LIFETIME_START %stack.2.b
191    LIFETIME_START %stack.3.tmp
192    ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
193    %6:gr64 = LEA64r %stack.3.tmp, 1, $noreg, 0, $noreg
194    %7:gr64 = LEA64r %stack.2.b, 1, $noreg, 0, $noreg
195    $rdi = COPY %6
196    $rsi = COPY %7
197    CALL64pcrel32 @_ZN1j1kEv, csr_64, implicit $rsp, implicit $ssp, implicit $rdi, implicit $rsi, implicit-def $rsp, implicit-def $ssp
198    ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
199    LIFETIME_END %stack.3.tmp
200    LIFETIME_END %stack.2.b
201    LIFETIME_END %stack.0.a
202    RET 0
203
204...
205