1 # RUN: llc -o - %s -mtriple=x86_64-pc-windows-msvc -run-pass=machinelicm | FileCheck %s
2 # RUN: llc -o - %s -mtriple=x86_64-pc-windows-msvc -passes=machinelicm | FileCheck %s
4 # This test checks that MachineLICM doesn't hoist loads out of funclets.
5 # Manually modified from the IR of the following C++ function by running
6 # llc -stop-after=machine-cp.
11 # void test(int n, int arg)
13 # for (int i = 0 ; i < n ; i++)
18 # // Two uses to get 'arg' allocated to a register
25 target triple = "x86_64-pc-windows-msvc"
27 define void @test(i32 %n, i32 %arg) personality ptr @__CxxFrameHandler3 {
29 %cmp3 = icmp sgt i32 %n, 0
30 br i1 %cmp3, label %for.body.preheader, label %for.cond.cleanup
32 for.body.preheader: ; preds = %entry
35 for.cond.cleanup: ; preds = %for.inc, %entry
38 for.body: ; preds = %for.body.preheader, %for.inc
39 %lsr.iv = phi i32 [ %n, %for.body.preheader ], [ %lsr.iv.next, %for.inc ]
40 invoke void @may_throw()
41 to label %for.inc unwind label %catch.dispatch
43 catch.dispatch: ; preds = %for.body
44 %0 = catchswitch within none [label %catch] unwind to caller
46 catch: ; preds = %catch.dispatch
47 %1 = catchpad within %0 [ptr null, i32 64, ptr null]
48 call void @use(i32 %arg) [ "funclet"(token %1) ]
49 call void @use(i32 %arg) [ "funclet"(token %1) ]
50 catchret from %1 to label %for.inc
52 for.inc: ; preds = %catch, %for.body
53 %lsr.iv.next = add i32 %lsr.iv, -1
54 %exitcond.not = icmp eq i32 %lsr.iv.next, 0
55 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
58 declare i32 @__CxxFrameHandler3(...)
60 declare void @may_throw()
62 declare void @use(i32)
68 tracksRegLiveness: true
73 tracksDebugUserValues: true
80 hasOpaqueSPAdjustment: true
82 - { id: 0, type: spill-slot, size: 4, alignment: 4 }
83 - { id: 1, type: spill-slot, size: 4, alignment: 4 }
84 machineFunctionInfo: {}
87 successors: %bb.1, %bb.2
90 MOV32mr %stack.1, 1, $noreg, 0, $noreg, $edx :: (store (s32) into %stack.1)
91 TEST32rr renamable $ecx, renamable $ecx, implicit-def $eflags
92 JCC_1 %bb.2, 14, implicit killed $eflags
99 bb.2.for.cond.cleanup:
103 successors: %bb.5, %bb.4
106 EH_LABEL <mcsymbol .Leh1>
107 MOV32mr %stack.0, 1, $noreg, 0, $noreg, killed renamable $ecx :: (store (s32) into %stack.0)
108 ADJCALLSTACKDOWN64 32, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
109 CALL64pcrel32 @may_throw, csr_win64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp
110 ADJCALLSTACKUP64 32, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
111 EH_LABEL <mcsymbol .Leh2>
114 bb.4.catch (landing-pad, ehfunclet-entry):
117 ADJCALLSTACKDOWN64 32, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
118 renamable $esi = MOV32rm %stack.1, 1, $noreg, 0, $noreg :: (load (s32) from %stack.1)
119 $ecx = COPY renamable $esi
120 CALL64pcrel32 @use, csr_win64, implicit $rsp, implicit $ssp, implicit $ecx, implicit-def $rsp, implicit-def $ssp
121 ADJCALLSTACKUP64 32, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
122 ADJCALLSTACKDOWN64 32, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
123 $ecx = COPY killed renamable $esi
124 CALL64pcrel32 @use, csr_win64, implicit $rsp, implicit $ssp, implicit $ecx, implicit-def $rsp, implicit-def $ssp
125 ADJCALLSTACKUP64 32, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
126 CATCHRET %bb.5, %bb.0
129 successors: %bb.2, %bb.3
131 renamable $ecx = MOV32rm %stack.0, 1, $noreg, 0, $noreg :: (load (s32) from %stack.0)
132 renamable $ecx = DEC32r killed renamable $ecx, implicit-def $eflags
133 JCC_1 %bb.2, 4, implicit killed $eflags
139 # CHECK: ADJCALLSTACKDOWN64
140 # CHECK-NEXT: renamable [[REG:\$[a-z0-9]+]] = MOV32rm %stack.1
141 # CHECK-NEXT: $ecx = COPY renamable [[REG]]
142 # CHECK-NEXT: CALL64pcrel32 @use