1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -instsimplify < %s | FileCheck %s
4 declare void @bar(i8* %a, i8* nonnull %b)
8 define i1 @caller1(i8* %x, i8* %y) {
9 ; CHECK-LABEL: @caller1(
10 ; CHECK-NEXT: call void @bar(i8* %x, i8* %y)
11 ; CHECK-NEXT: ret i1 false
13 call void @bar(i8* %x, i8* %y)
14 %null_check = icmp eq i8* %y, null
18 ; Don't know anything about 'y'.
20 define 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]]
26 call void @bar(i8* %y, i8* %x)
27 %null_check = icmp eq i8* %y, null
31 ; 'y' must be nonnull.
33 define i1 @caller3(i8* %x, i8* %y) {
34 ; CHECK-LABEL: @caller3(
35 ; CHECK-NEXT: call void @bar(i8* %x, i8* %y)
36 ; CHECK-NEXT: ret i1 true
38 call void @bar(i8* %x, i8* %y)
39 %null_check = icmp ne i8* %y, null
43 ; FIXME: The call is guaranteed to execute, so 'y' must be nonnull throughout.
45 define i1 @caller4(i8* %x, i8* %y) {
46 ; CHECK-LABEL: @caller4(
47 ; CHECK-NEXT: [[NULL_CHECK:%.*]] = icmp ne i8* %y, null
48 ; CHECK-NEXT: call void @bar(i8* %x, i8* %y)
49 ; CHECK-NEXT: ret i1 [[NULL_CHECK]]
51 %null_check = icmp ne i8* %y, null
52 call void @bar(i8* %x, i8* %y)
56 ; The call to bar() does not dominate the null check, so no change.
58 define 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
63 ; CHECK-NEXT: ret i1 [[NULL_CHECK]]
65 ; CHECK-NEXT: call void @bar(i8* %x, i8* %y)
66 ; CHECK-NEXT: ret i1 [[NULL_CHECK]]
68 %null_check = icmp eq i8* %y, null
69 br i1 %null_check, label %t, label %f
73 call void @bar(i8* %x, i8* %y)
77 ; Make sure that an invoke works similarly to a call.
79 declare i32 @esfp(...)
81 define 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
86 ; CHECK-NEXT: ret i1 false
88 invoke void @bar(i8* %x, i8* nonnull %y)
89 to label %cont unwind label %exc
92 %null_check = icmp eq i8* %y, null
96 %lp = landingpad { i8*, i32 }
97 filter [0 x i8*] zeroinitializer
101 declare i8* @returningPtr(i8* returned %p)
103 define i1 @nonnullReturnTest(i8* nonnull %x) {
104 ; CHECK-LABEL: @nonnullReturnTest(
105 ; CHECK-NEXT: %x2 = call i8* @returningPtr(i8* %x)
106 ; CHECK-NEXT: ret i1 false
107 %x2 = call i8* @returningPtr(i8* %x)
108 %null_check = icmp eq i8* %x2, null
112 define i1 @unknownReturnTest(i8* %x) {
113 ; CHECK-LABEL: @unknownReturnTest(
114 ; CHECK-NEXT: %x2 = call i8* @returningPtr(i8* %x)
115 ; CHECK-NEXT: %null_check = icmp eq i8* %x2, null
116 ; CHECK-NEXT: ret i1 %null_check
117 %x2 = call i8* @returningPtr(i8* %x)
118 %null_check = icmp eq i8* %x2, null