[SEH] Push reloads of the SEH code past phi nodes
[oota-llvm.git] / test / CodeGen / WinEH / seh-exception-code2.ll
1 ; RUN: opt -winehprepare -S < %s | FileCheck %s
2
3 ; WinEHPrepare was crashing during phi demotion.
4
5 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
6 target triple = "x86_64-pc-windows-msvc18.0.0"
7
8 declare i32 @__C_specific_handler(...)
9
10 @str = linkonce_odr unnamed_addr constant [16 x i8] c"caught it! %lx\0A\00", align 1
11
12 declare void @maycrash()
13 declare void @finally(i1 %abnormal)
14 declare i32 @printf(i8* nocapture readonly, ...)
15 declare i32 @llvm.eh.typeid.for(i8*)
16
17 ; Function Attrs: nounwind uwtable
18 define void @doit() personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
19 entry:
20   invoke void @maycrash()
21           to label %invoke.cont unwind label %lpad.1
22
23 invoke.cont:                                      ; preds = %entry
24   invoke void @maycrash()
25           to label %__try.cont unwind label %lpad
26
27 lpad:                                             ; preds = %entry
28   %lp0 = landingpad { i8*, i32 }
29           cleanup
30           catch i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@doit@@" to i8*)
31   %ehptr.0 = extractvalue { i8*, i32 } %lp0, 0
32   %ehsel.0 = extractvalue { i8*, i32 } %lp0, 1
33   call void @finally(i1 true)
34   br label %ehdispatch
35
36 lpad.1:                                           ; preds = %invoke.cont, %lpad
37   %lp1 = landingpad { i8*, i32 }
38           catch i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@doit@@" to i8*)
39   %ehptr.1 = extractvalue { i8*, i32 } %lp1, 0
40   %ehsel.1 = extractvalue { i8*, i32 } %lp1, 1
41   br label %ehdispatch
42
43 ehdispatch:
44   %ehptr.2 = phi i8* [ %ehptr.0, %lpad ], [ %ehptr.1, %lpad.1 ]
45   %ehsel.2 = phi i32 [ %ehsel.0, %lpad ], [ %ehsel.1, %lpad.1 ]
46   %mysel = call i32 @llvm.eh.typeid.for(i8* bitcast (i32 (i8*, i8*)* @"\01?filt$0@0@doit@@" to i8*))
47   %matches = icmp eq i32 %ehsel.2, %mysel
48   br i1 %matches, label %__except, label %eh.resume
49
50 __except:                                         ; preds = %lpad, %lpad.1
51   %t4 = ptrtoint i8* %ehptr.2 to i64
52   %t5 = trunc i64 %t4 to i32
53   %call = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0), i32 %t5)
54   br label %__try.cont
55
56 __try.cont:                                       ; preds = %invoke.cont, %__except
57   call void @finally(i1 false)
58   ret void
59
60 eh.resume:
61   %ehvals0 = insertvalue { i8*, i32 } undef, i8* %ehptr.2, 0
62   %ehvals = insertvalue { i8*, i32 } %ehvals0, i32 %ehsel.2, 1
63   resume { i8*, i32 } %ehvals
64 }
65
66 define internal i32 @"\01?filt$0@0@doit@@"(i8* %exception_pointers, i8* %frame_pointer) #1 {
67 entry:
68   %0 = bitcast i8* %exception_pointers to { i32*, i8* }*
69   %1 = getelementptr inbounds { i32*, i8* }, { i32*, i8* }* %0, i32 0, i32 0
70   %2 = load i32*, i32** %1
71   %3 = load i32, i32* %2
72   %cmp = icmp eq i32 %3, -1073741819
73   %4 = zext i1 %cmp to i32
74   ret i32 %4
75 }
76
77 ; CHECK-LABEL: define void @doit()
78 ; CHECK: %lp0 = landingpad { i8*, i32 }
79 ; CHECK-NEXT: cleanup
80 ; CHECK-NEXT: catch i8*
81 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions({{.*}})
82 ; CHECK-NEXT: indirectbr i8* %{{[^,]*}}, [label %__except]
83 ;
84 ; CHECK: %lp1 = landingpad { i8*, i32 }
85 ; CHECK-NEXT: catch i8*
86 ; CHECK-NEXT: call i8* (...) @llvm.eh.actions({{.*}})
87 ; CHECK-NEXT: indirectbr i8* %{{[^,]*}}, [label %__except]
88 ;
89 ; CHECK: __except:
90 ; CHECK: call i32 @llvm.eh.exceptioncode()
91 ; CHECK: call i32 (i8*, ...) @printf