1 # RUN: llc -o - %s -mtriple=x86_64-pc-windows-msvc -run-pass=machinelicm | FileCheck %s
3 # This test checks that MachineLICM doesn't hoist loads out of funclets.
4 # Manually modified from the IR of the following C++ function by running
5 # llc -stop-after=machine-cp.
10 # void test(int n, int arg)
12 # for (int i = 0 ; i < n ; i++)
17 # // Two uses to get 'arg' allocated to a register
24 target triple = "x86_64-pc-windows-msvc"
26 define void @test(i32 %n, i32 %arg) personality ptr @__CxxFrameHandler3 {
28 %cmp3 = icmp sgt i32 %n, 0
29 br i1 %cmp3, label %for.body.preheader, label %for.cond.cleanup
31 for.body.preheader: ; preds = %entry
34 for.cond.cleanup: ; preds = %for.inc, %entry
37 for.body: ; preds = %for.body.preheader, %for.inc
38 %lsr.iv = phi i32 [ %n, %for.body.preheader ], [ %lsr.iv.next, %for.inc ]
39 invoke void @may_throw()
40 to label %for.inc unwind label %catch.dispatch
42 catch.dispatch: ; preds = %for.body
43 %0 = catchswitch within none [label %catch] unwind to caller
45 catch: ; preds = %catch.dispatch
46 %1 = catchpad within %0 [ptr null, i32 64, ptr null]
47 call void @use(i32 %arg) [ "funclet"(token %1) ]
48 call void @use(i32 %arg) [ "funclet"(token %1) ]
49 catchret from %1 to label %for.inc
51 for.inc: ; preds = %catch, %for.body
52 %lsr.iv.next = add i32 %lsr.iv, -1
53 %exitcond.not = icmp eq i32 %lsr.iv.next, 0
54 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
57 declare i32 @__CxxFrameHandler3(...)
59 declare void @may_throw()
61 declare void @use(i32)
67 tracksRegLiveness: true
72 tracksDebugUserValues: true
79 hasOpaqueSPAdjustment: true
81 - { id: 0, type: spill-slot, size: 4, alignment: 4 }
82 - { id: 1, type: spill-slot, size: 4, alignment: 4 }
83 machineFunctionInfo: {}
86 successors: %bb.1, %bb.2
89 MOV32mr %stack.1, 1, $noreg, 0, $noreg, $edx :: (store (s32) into %stack.1)
90 TEST32rr renamable $ecx, renamable $ecx, implicit-def $eflags
91 JCC_1 %bb.2, 14, implicit killed $eflags
98 bb.2.for.cond.cleanup:
102 successors: %bb.5, %bb.4
105 EH_LABEL <mcsymbol .Leh1>
106 MOV32mr %stack.0, 1, $noreg, 0, $noreg, killed renamable $ecx :: (store (s32) into %stack.0)
107 ADJCALLSTACKDOWN64 32, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
108 CALL64pcrel32 @may_throw, csr_win64, implicit $rsp, implicit $ssp, implicit-def $rsp, implicit-def $ssp
109 ADJCALLSTACKUP64 32, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
110 EH_LABEL <mcsymbol .Leh2>
113 bb.4.catch (landing-pad, ehfunclet-entry):
116 ADJCALLSTACKDOWN64 32, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
117 renamable $esi = MOV32rm %stack.1, 1, $noreg, 0, $noreg :: (load (s32) from %stack.1)
118 $ecx = COPY renamable $esi
119 CALL64pcrel32 @use, csr_win64, implicit $rsp, implicit $ssp, implicit $ecx, implicit-def $rsp, implicit-def $ssp
120 ADJCALLSTACKUP64 32, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
121 ADJCALLSTACKDOWN64 32, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
122 $ecx = COPY killed renamable $esi
123 CALL64pcrel32 @use, csr_win64, implicit $rsp, implicit $ssp, implicit $ecx, implicit-def $rsp, implicit-def $ssp
124 ADJCALLSTACKUP64 32, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp
125 CATCHRET %bb.5, %bb.0
128 successors: %bb.2, %bb.3
130 renamable $ecx = MOV32rm %stack.0, 1, $noreg, 0, $noreg :: (load (s32) from %stack.0)
131 renamable $ecx = DEC32r killed renamable $ecx, implicit-def $eflags
132 JCC_1 %bb.2, 4, implicit killed $eflags
138 # CHECK: ADJCALLSTACKDOWN64
139 # CHECK-NEXT: renamable [[REG:\$[a-z0-9]+]] = MOV32rm %stack.1
140 # CHECK-NEXT: $ecx = COPY renamable [[REG]]
141 # CHECK-NEXT: CALL64pcrel32 @use