summaryrefslogtreecommitdiffstats
path: root/llvm/test/CodeGen/X86/branchfolding-catchpads.ll
blob: 0468b3c314f6166c7379e62de08492d2783e4fdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
; RUN: llc -mtriple=x86_64-pc-windows-msvc < %s | FileCheck %s

declare i32 @__CxxFrameHandler3(...)

declare void @throw()
declare i16 @f()

define i16 @test1(i16 %a, i8* %b) personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
entry:
  %cmp = icmp eq i16 %a, 10
  br i1 %cmp, label %if.then, label %if.else

if.then:
  %call1 = invoke i16 @f()
          to label %cleanup unwind label %catch.dispatch

if.else:
  %call2 = invoke i16 @f()
          to label %cleanup unwind label %catch.dispatch

catch.dispatch:
  %cs = catchswitch within none [ label %catch, label %catch.2 ] unwind to caller

catch:
  catchpad within %cs [i8* null, i32 8, i8* null]
  call void @throw() noreturn
  br label %unreachable

catch.2:
  catchpad within %cs [i8* null, i32 64, i8* null]
  store i8 1, i8* %b
  call void @throw() noreturn
  br label %unreachable

cleanup:
  %retval = phi i16 [ %call1, %if.then ], [ %call2, %if.else ]
  ret i16 %retval

unreachable:
  unreachable
}

; This test verifies the case where two funclet blocks meet the old criteria
; to be placed at the end.  The order of the blocks is not important for the
; purposes of this test.  The failure mode is an infinite loop during
; compilation.
;
; CHECK-LABEL: .def     test1;

define i16 @test2(i16 %a, i8* %b) personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
entry:
  %cmp = icmp eq i16 %a, 10
  br i1 %cmp, label %if.then, label %if.else

if.then:
  %call1 = invoke i16 @f()
          to label %cleanup unwind label %catch.dispatch

if.else:
  %call2 = invoke i16 @f()
          to label %cleanup unwind label %catch.dispatch

catch.dispatch:
  %cs = catchswitch within none [ label %catch, label %catch.2, label %catch.3 ] unwind to caller

catch:
  catchpad within %cs [i8* null, i32 8, i8* null]
  call void @throw() noreturn
  br label %unreachable

catch.2:
  %c2 = catchpad within %cs [i8* null, i32 32, i8* null]
  store i8 1, i8* %b
  catchret from %c2 to label %cleanup

catch.3:
  %c3 = catchpad within %cs [i8* null, i32 64, i8* null]
  store i8 2, i8* %b
  catchret from %c3 to label %cleanup

cleanup:
  %retval = phi i16 [ %call1, %if.then ], [ %call2, %if.else ], [ -1, %catch.2 ], [ -1, %catch.3 ]
  ret i16 %retval

unreachable:
  unreachable
}

; This test verifies the case where three funclet blocks all meet the old
; criteria to be placed at the end.  The order of the blocks is not important
; for the purposes of this test.  The failure mode is an infinite loop during
; compilation.
;
; CHECK-LABEL: .def     test2;

OpenPOWER on IntegriCloud