blob: 93ef4f8c4c48a49031a0381a28b881d2469fb428 [file] [log] [blame]
Sanjay Patel5865d122016-12-31 19:23:26 +00001; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -S -instsimplify < %s | FileCheck %s
3
4declare void @bar(i8* %a, i8* nonnull %b)
5
6; 'y' must be nonnull.
7
8define i1 @caller1(i8* %x, i8* %y) {
9; CHECK-LABEL: @caller1(
10; CHECK-NEXT: call void @bar(i8* %x, i8* %y)
Sanjay Patel97e4b9872017-02-12 15:35:34 +000011; CHECK-NEXT: ret i1 false
Sanjay Patel5865d122016-12-31 19:23:26 +000012;
13 call void @bar(i8* %x, i8* %y)
14 %null_check = icmp eq i8* %y, null
15 ret i1 %null_check
16}
17
18; Don't know anything about 'y'.
19
20define i1 @caller2(i8* %x, i8* %y) {
21; CHECK-LABEL: @caller2(
22; CHECK-NEXT: call void @bar(i8* %y, i8* %x)
23; CHECK-NEXT: [[NULL_CHECK:%.*]] = icmp eq i8* %y, null
24; CHECK-NEXT: ret i1 [[NULL_CHECK]]
25;
26 call void @bar(i8* %y, i8* %x)
27 %null_check = icmp eq i8* %y, null
28 ret i1 %null_check
29}
30
31; 'y' must be nonnull.
32
33define i1 @caller3(i8* %x, i8* %y) {
34; CHECK-LABEL: @caller3(
35; CHECK-NEXT: call void @bar(i8* %x, i8* %y)
Sanjay Patel97e4b9872017-02-12 15:35:34 +000036; CHECK-NEXT: ret i1 true
Sanjay Patel5865d122016-12-31 19:23:26 +000037;
38 call void @bar(i8* %x, i8* %y)
39 %null_check = icmp ne i8* %y, null
40 ret i1 %null_check
41}
42
Sanjay Patel97e4b9872017-02-12 15:35:34 +000043; FIXME: The call is guaranteed to execute, so 'y' must be nonnull throughout.
Sanjay Patel5865d122016-12-31 19:23:26 +000044
45define i1 @caller4(i8* %x, i8* %y) {
46; CHECK-LABEL: @caller4(
Sanjay Patel5865d122016-12-31 19:23:26 +000047; CHECK-NEXT: [[NULL_CHECK:%.*]] = icmp ne i8* %y, null
Sanjay Patel97e4b9872017-02-12 15:35:34 +000048; CHECK-NEXT: call void @bar(i8* %x, i8* %y)
Sanjay Patel5865d122016-12-31 19:23:26 +000049; CHECK-NEXT: ret i1 [[NULL_CHECK]]
50;
Sanjay Patel5865d122016-12-31 19:23:26 +000051 %null_check = icmp ne i8* %y, null
Sanjay Patel97e4b9872017-02-12 15:35:34 +000052 call void @bar(i8* %x, i8* %y)
Sanjay Patel5865d122016-12-31 19:23:26 +000053 ret i1 %null_check
54}
55
Sanjay Patel97e4b9872017-02-12 15:35:34 +000056; The call to bar() does not dominate the null check, so no change.
57
58define i1 @caller5(i8* %x, i8* %y) {
59; CHECK-LABEL: @caller5(
60; CHECK-NEXT: [[NULL_CHECK:%.*]] = icmp eq i8* %y, null
61; CHECK-NEXT: br i1 [[NULL_CHECK]], label %t, label %f
62; CHECK: t:
63; CHECK-NEXT: ret i1 [[NULL_CHECK]]
64; CHECK: f:
65; CHECK-NEXT: call void @bar(i8* %x, i8* %y)
66; CHECK-NEXT: ret i1 [[NULL_CHECK]]
67;
68 %null_check = icmp eq i8* %y, null
69 br i1 %null_check, label %t, label %f
70t:
71 ret i1 %null_check
72f:
73 call void @bar(i8* %x, i8* %y)
74 ret i1 %null_check
75}
76
77; Make sure that an invoke works similarly to a call.
78
79declare i32 @esfp(...)
80
81define i1 @caller6(i8* %x, i8* %y) personality i8* bitcast (i32 (...)* @esfp to i8*){
82; CHECK-LABEL: @caller6(
83; CHECK-NEXT: invoke void @bar(i8* %x, i8* nonnull %y)
84; CHECK-NEXT: to label %cont unwind label %exc
85; CHECK: cont:
86; CHECK-NEXT: ret i1 false
87;
88 invoke void @bar(i8* %x, i8* nonnull %y)
89 to label %cont unwind label %exc
90
91cont:
92 %null_check = icmp eq i8* %y, null
93 ret i1 %null_check
94
95exc:
96 %lp = landingpad { i8*, i32 }
97 filter [0 x i8*] zeroinitializer
98 unreachable
99}
100