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