xref: /llvm-project/llvm/test/CodeGen/X86/regalloc-spill-at-ehpad.ll (revision 2f448bf509432c1a19ec46ab8cbc7353c03c6280)
1; RUN: llc -regalloc=greedy -mtriple=x86_64-pc-windows-msvc  < %s -o - | FileCheck %s
2
3; This test checks for proper handling of a condition where the greedy register
4; allocator encounters a very short interval that contains no uses but does
5; contain an EH pad unwind edge, which requires spilling.  Previously the
6; register allocator marked a interval like this as unspillable, resulting in
7; a compilation failure.
8
9
10; The following checks that the value %p is reloaded within the catch handler.
11; CHECK-LABEL: "?catch$8@?0?test@4HA":
12; CHECK:           .seh_endprologue
13; CHECK:           movq    -16(%rbp), %rax
14; CHECK:           movb    $0, (%rax)
15
16define ptr @test(ptr %a) personality ptr @__CxxFrameHandler3 {
17entry:
18  %call = call i32 @f()
19  br i1 undef, label %if.end, label %if.else
20
21if.else:                                          ; preds = %entry
22  br i1 undef, label %cond.false.i, label %if.else.else
23
24if.else.else:                                     ; preds = %if.else
25  br i1 undef, label %cond.true.i, label %cond.false.i
26
27cond.true.i:                                      ; preds = %if.else.else
28  br label %invoke.cont
29
30cond.false.i:                                     ; preds = %if.else.else, %if.else
31  %call.i = invoke i32 @f()
32          to label %invoke.cont unwind label %catch.dispatch
33
34catch.dispatch:                                   ; preds = %cond.false.i
35  %tmp0 = catchswitch within none [label %catch] unwind label %ehcleanup
36
37catch:                                            ; preds = %catch.dispatch
38  %tmp1 = catchpad within %tmp0 [ptr null, i32 64, ptr null]
39  store i8 0, ptr %a, align 8
40  invoke void @_CxxThrowException(ptr null, ptr null) [ "funclet"(token %tmp1) ]
41          to label %noexc unwind label %ehcleanup
42
43noexc:                                            ; preds = %catch
44  unreachable
45
46invoke.cont:                                      ; preds = %cond.false.i, %cond.true.i
47  %cond.i = phi i32 [ %call, %cond.true.i ], [ %call.i, %cond.false.i ]
48  %cmp = icmp eq i32 %cond.i, -1
49  %tmp3 = select i1 %cmp, i32 4, i32 0
50  br label %if.end
51
52if.end:                                           ; preds = %invoke.cont, %entry
53  %state.0 = phi i32 [ %tmp3, %invoke.cont ], [ 4, %entry ]
54  invoke void @g(ptr %a, i32 %state.0)
55          to label %invoke.cont.1 unwind label %ehcleanup
56
57invoke.cont.1:                                    ; preds = %if.end
58  ret ptr %a
59
60ehcleanup:                                        ; preds = %if.end, %catch, %catch.dispatch
61  %tmp4 = cleanuppad within none []
62  cleanupret from %tmp4 unwind to caller
63}
64
65%eh.ThrowInfo = type { i32, i32, i32, i32 }
66
67declare i32 @__CxxFrameHandler3(...)
68
69declare void @_CxxThrowException(ptr, ptr)
70
71declare i32 @f()
72declare void @g(ptr, i32)
73