1; RUN: opt -S -consthoist < %s | FileCheck %s
2; RUN: opt -S -passes=consthoist < %s | FileCheck %s
3
4target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
5target triple = "x86_64-apple-macosx10.9.0"
6
7; PR18626
8define i8* @test1(i1 %cmp, i64* %tmp) {
9entry:
10  call void @foo(i8* inttoptr (i64 68719476735 to i8*))
11  br i1 %cmp, label %if.end, label %return
12
13if.end:                                           ; preds = %bb1
14  call void @foo(i8* inttoptr (i64 68719476736 to i8*))
15  br label %return
16
17return:
18  %retval.0 = phi i8* [ null, %entry ], [ inttoptr (i64 68719476736 to i8*), %if.end ]
19  store i64 1172321806, i64* %tmp
20  ret i8* %retval.0
21
22; CHECK-LABEL: @test1
23; CHECK: if.end:
24; CHECK: %2 = inttoptr i64 %const to i8*
25; CHECK-NEXT: br
26; CHECK: return:
27; CHECK-NEXT: %retval.0 = phi i8* [ null, %entry ], [ %2, %if.end ]
28}
29
30define void @test2(i1 %cmp, i64** %tmp) {
31entry:
32  call void @foo(i8* inttoptr (i64 68719476736 to i8*))
33  br i1 %cmp, label %if.end, label %return
34
35if.end:                                           ; preds = %bb1
36  call void @foo(i8* inttoptr (i64 68719476736 to i8*))
37  br label %return
38
39return:
40  store i64* inttoptr (i64 68719476735 to i64*), i64** %tmp
41  ret void
42
43; CHECK-LABEL: @test2
44; CHECK: return:
45; CHECK-NEXT: %const_mat = add i64 %const, -1
46; CHECK-NEXT: inttoptr i64 %const_mat to i64*
47}
48
49declare void @foo(i8*)
50
51; PR18768
52define i32 @test3(i1 %c) {
53entry:
54  br i1 %c, label %if.then, label %if.end3
55
56if.then:                                          ; preds = %entry
57  br label %if.end3
58
59if.end3:                                          ; preds = %if.then, %entry
60  %d.0 = phi i32* [ inttoptr (i64 985162435264511 to i32*), %entry ], [ null, %if.then ]
61  %cmp4 = icmp eq i32* %d.0, inttoptr (i64 985162435264511 to i32*)
62  %cmp6 = icmp eq i32* %d.0, inttoptr (i64 985162418487296 to i32*)
63  %or = or i1 %cmp4, %cmp6
64  br i1 %or, label %if.then8, label %if.end9
65
66if.then8:                                         ; preds = %if.end3
67  ret i32 1
68
69if.end9:                                          ; preds = %if.then8, %if.end3
70  ret i32 undef
71}
72
73; <rdar://problem/16394449>
74define i64 @switch_test1(i64 %a) {
75; CHECK-LABEL: @switch_test1
76; CHECK: %0 = phi i64 [ %const, %case2 ], [ %const_mat, %Entry ], [ %const_mat, %Entry ]
77Entry:
78  %sel = add i64 %a, 4519019440
79  switch i64 %sel, label %fail [
80    i64 462, label %continuation
81    i64 449, label %case2
82    i64 443, label %continuation
83  ]
84
85case2:
86  br label %continuation
87
88continuation:
89  %0 = phi i64 [ 4519019440, %case2 ], [ 4519019460, %Entry ], [ 4519019460, %Entry ]
90  ret i64 0;
91
92fail:
93  ret i64 -1;
94}
95
96define i64 @switch_test2(i64 %a) {
97; CHECK-LABEL: @switch_test2
98; CHECK: %2 = phi i64* [ %1, %case2 ], [ %0, %Entry ], [ %0, %Entry ]
99Entry:
100  %sel = add i64 %a, 4519019440
101  switch i64 %sel, label %fail [
102    i64 462, label %continuation
103    i64 449, label %case2
104    i64 443, label %continuation
105  ]
106
107case2:
108  br label %continuation
109
110continuation:
111  %0 = phi i64* [ inttoptr(i64 4519019440 to i64*), %case2 ], [ inttoptr(i64 4519019460 to i64*), %Entry ], [ inttoptr(i64 4519019460 to i64*), %Entry ]
112  ret i64 0;
113
114fail:
115  ret i64 -1;
116}
117
118