Sanjay Patel | 5865d12 | 2016-12-31 19:23:26 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| 2 | ; RUN: opt -S -instsimplify < %s | FileCheck %s |
| 3 | |
| 4 | declare void @bar(i8* %a, i8* nonnull %b) |
| 5 | |
| 6 | ; 'y' must be nonnull. |
| 7 | |
| 8 | define i1 @caller1(i8* %x, i8* %y) { |
| 9 | ; CHECK-LABEL: @caller1( |
| 10 | ; CHECK-NEXT: call void @bar(i8* %x, i8* %y) |
Sanjay Patel | 97e4b987 | 2017-02-12 15:35:34 +0000 | [diff] [blame] | 11 | ; CHECK-NEXT: ret i1 false |
Sanjay Patel | 5865d12 | 2016-12-31 19:23:26 +0000 | [diff] [blame] | 12 | ; |
| 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 | |
| 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]] |
| 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 | |
| 33 | define i1 @caller3(i8* %x, i8* %y) { |
| 34 | ; CHECK-LABEL: @caller3( |
| 35 | ; CHECK-NEXT: call void @bar(i8* %x, i8* %y) |
Sanjay Patel | 97e4b987 | 2017-02-12 15:35:34 +0000 | [diff] [blame] | 36 | ; CHECK-NEXT: ret i1 true |
Sanjay Patel | 5865d12 | 2016-12-31 19:23:26 +0000 | [diff] [blame] | 37 | ; |
| 38 | call void @bar(i8* %x, i8* %y) |
| 39 | %null_check = icmp ne i8* %y, null |
| 40 | ret i1 %null_check |
| 41 | } |
| 42 | |
Sanjay Patel | 97e4b987 | 2017-02-12 15:35:34 +0000 | [diff] [blame] | 43 | ; FIXME: The call is guaranteed to execute, so 'y' must be nonnull throughout. |
Sanjay Patel | 5865d12 | 2016-12-31 19:23:26 +0000 | [diff] [blame] | 44 | |
| 45 | define i1 @caller4(i8* %x, i8* %y) { |
| 46 | ; CHECK-LABEL: @caller4( |
Sanjay Patel | 5865d12 | 2016-12-31 19:23:26 +0000 | [diff] [blame] | 47 | ; CHECK-NEXT: [[NULL_CHECK:%.*]] = icmp ne i8* %y, null |
Sanjay Patel | 97e4b987 | 2017-02-12 15:35:34 +0000 | [diff] [blame] | 48 | ; CHECK-NEXT: call void @bar(i8* %x, i8* %y) |
Sanjay Patel | 5865d12 | 2016-12-31 19:23:26 +0000 | [diff] [blame] | 49 | ; CHECK-NEXT: ret i1 [[NULL_CHECK]] |
| 50 | ; |
Sanjay Patel | 5865d12 | 2016-12-31 19:23:26 +0000 | [diff] [blame] | 51 | %null_check = icmp ne i8* %y, null |
Sanjay Patel | 97e4b987 | 2017-02-12 15:35:34 +0000 | [diff] [blame] | 52 | call void @bar(i8* %x, i8* %y) |
Sanjay Patel | 5865d12 | 2016-12-31 19:23:26 +0000 | [diff] [blame] | 53 | ret i1 %null_check |
| 54 | } |
| 55 | |
Sanjay Patel | 97e4b987 | 2017-02-12 15:35:34 +0000 | [diff] [blame] | 56 | ; The call to bar() does not dominate the null check, so no change. |
| 57 | |
| 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 |
| 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 |
| 70 | t: |
| 71 | ret i1 %null_check |
| 72 | f: |
| 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 | |
| 79 | declare i32 @esfp(...) |
| 80 | |
| 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 |
| 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 | |
| 91 | cont: |
| 92 | %null_check = icmp eq i8* %y, null |
| 93 | ret i1 %null_check |
| 94 | |
| 95 | exc: |
| 96 | %lp = landingpad { i8*, i32 } |
| 97 | filter [0 x i8*] zeroinitializer |
| 98 | unreachable |
| 99 | } |
| 100 | |