Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -instsimplify -S | FileCheck %s |
| 2 | |
| 3 | ; In the next 8 tests (4 commutes * 2 (and/or)), eliminate the simple (not) null |
| 4 | ; check because that compare is implied by the masked compare of the same operand. |
| 5 | ; Vary types between scalar and vector and weird for extra coverage. |
| 6 | |
| 7 | ; or (icmp eq (and X, ?), 0), (icmp eq X, 0) --> icmp eq (and X, ?), 0 |
| 8 | |
| 9 | define i1 @or_cmps_eq_zero_with_mask_commute1(i64 %x, i64 %y) { |
| 10 | ; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute1( |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 11 | ; CHECK-NEXT: [[SOMEBITS:%.*]] = and i64 %x, %y |
| 12 | ; CHECK-NEXT: [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq i64 [[SOMEBITS]], 0 |
Sanjay Patel | 6ef6aa9 | 2018-01-11 23:27:37 +0000 | [diff] [blame] | 13 | ; CHECK-NEXT: ret i1 [[SOMEBITS_ARE_ZERO]] |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 14 | ; |
| 15 | %isnull = icmp eq i64 %x, 0 |
| 16 | %somebits = and i64 %x, %y |
| 17 | %somebits_are_zero = icmp eq i64 %somebits, 0 |
| 18 | %r = or i1 %somebits_are_zero, %isnull |
| 19 | ret i1 %r |
| 20 | } |
| 21 | |
| 22 | ; or (icmp eq X, 0), (icmp eq (and X, ?), 0) --> icmp eq (and X, ?), 0 |
| 23 | |
| 24 | define <2 x i1> @or_cmps_eq_zero_with_mask_commute2(<2 x i64> %x, <2 x i64> %y) { |
| 25 | ; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute2( |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 26 | ; CHECK-NEXT: [[SOMEBITS:%.*]] = and <2 x i64> %x, %y |
| 27 | ; CHECK-NEXT: [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq <2 x i64> [[SOMEBITS]], zeroinitializer |
Sanjay Patel | 6ef6aa9 | 2018-01-11 23:27:37 +0000 | [diff] [blame] | 28 | ; CHECK-NEXT: ret <2 x i1> [[SOMEBITS_ARE_ZERO]] |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 29 | ; |
| 30 | %isnull = icmp eq <2 x i64> %x, zeroinitializer |
| 31 | %somebits = and <2 x i64> %x, %y |
| 32 | %somebits_are_zero = icmp eq <2 x i64> %somebits, zeroinitializer |
| 33 | %r = or <2 x i1> %isnull, %somebits_are_zero |
| 34 | ret <2 x i1> %r |
| 35 | } |
| 36 | |
| 37 | ; or (icmp eq (and ?, X), 0), (icmp eq X, 0) --> icmp eq (and ?, X), 0 |
| 38 | |
| 39 | define i1 @or_cmps_eq_zero_with_mask_commute3(i4 %x, i4 %y) { |
| 40 | ; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute3( |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 41 | ; CHECK-NEXT: [[SOMEBITS:%.*]] = and i4 %y, %x |
| 42 | ; CHECK-NEXT: [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq i4 [[SOMEBITS]], 0 |
Sanjay Patel | 6ef6aa9 | 2018-01-11 23:27:37 +0000 | [diff] [blame] | 43 | ; CHECK-NEXT: ret i1 [[SOMEBITS_ARE_ZERO]] |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 44 | ; |
| 45 | %isnull = icmp eq i4 %x, 0 |
| 46 | %somebits = and i4 %y, %x |
| 47 | %somebits_are_zero = icmp eq i4 %somebits, 0 |
| 48 | %r = or i1 %somebits_are_zero, %isnull |
| 49 | ret i1 %r |
| 50 | } |
| 51 | |
| 52 | ; or (icmp eq X, 0), (icmp eq (and ?, X), 0) --> icmp eq (and ?, X), 0 |
| 53 | |
| 54 | define <2 x i1> @or_cmps_eq_zero_with_mask_commute4(<2 x i4> %x, <2 x i4> %y) { |
| 55 | ; CHECK-LABEL: @or_cmps_eq_zero_with_mask_commute4( |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 56 | ; CHECK-NEXT: [[SOMEBITS:%.*]] = and <2 x i4> %y, %x |
| 57 | ; CHECK-NEXT: [[SOMEBITS_ARE_ZERO:%.*]] = icmp eq <2 x i4> [[SOMEBITS]], zeroinitializer |
Sanjay Patel | 6ef6aa9 | 2018-01-11 23:27:37 +0000 | [diff] [blame] | 58 | ; CHECK-NEXT: ret <2 x i1> [[SOMEBITS_ARE_ZERO]] |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 59 | ; |
| 60 | %isnull = icmp eq <2 x i4> %x, zeroinitializer |
| 61 | %somebits = and <2 x i4> %y, %x |
| 62 | %somebits_are_zero = icmp eq <2 x i4> %somebits, zeroinitializer |
| 63 | %r = or <2 x i1> %isnull, %somebits_are_zero |
| 64 | ret <2 x i1> %r |
| 65 | } |
| 66 | |
| 67 | ; and (icmp ne (and X, ?), 0), (icmp ne X, 0) --> icmp ne (and X, ?), 0 |
| 68 | |
| 69 | define <3 x i1> @and_cmps_eq_zero_with_mask_commute1(<3 x i4> %x, <3 x i4> %y) { |
| 70 | ; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute1( |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 71 | ; CHECK-NEXT: [[SOMEBITS:%.*]] = and <3 x i4> %x, %y |
| 72 | ; CHECK-NEXT: [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne <3 x i4> [[SOMEBITS]], zeroinitializer |
Sanjay Patel | 6ef6aa9 | 2018-01-11 23:27:37 +0000 | [diff] [blame] | 73 | ; CHECK-NEXT: ret <3 x i1> [[SOMEBITS_ARE_NOT_ZERO]] |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 74 | ; |
| 75 | %isnotnull = icmp ne <3 x i4> %x, zeroinitializer |
| 76 | %somebits = and <3 x i4> %x, %y |
| 77 | %somebits_are_not_zero = icmp ne <3 x i4> %somebits, zeroinitializer |
| 78 | %r = and <3 x i1> %somebits_are_not_zero, %isnotnull |
| 79 | ret <3 x i1> %r |
| 80 | } |
| 81 | |
| 82 | ; and (icmp ne X, 0), (icmp ne (and X, ?), 0) --> icmp ne (and X, ?), 0 |
| 83 | |
| 84 | define i1 @and_cmps_eq_zero_with_mask_commute2(i4 %x, i4 %y) { |
| 85 | ; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute2( |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 86 | ; CHECK-NEXT: [[SOMEBITS:%.*]] = and i4 %x, %y |
| 87 | ; CHECK-NEXT: [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne i4 [[SOMEBITS]], 0 |
Sanjay Patel | 6ef6aa9 | 2018-01-11 23:27:37 +0000 | [diff] [blame] | 88 | ; CHECK-NEXT: ret i1 [[SOMEBITS_ARE_NOT_ZERO]] |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 89 | ; |
| 90 | %isnotnull = icmp ne i4 %x, 0 |
| 91 | %somebits = and i4 %x, %y |
| 92 | %somebits_are_not_zero = icmp ne i4 %somebits, 0 |
| 93 | %r = and i1 %isnotnull, %somebits_are_not_zero |
| 94 | ret i1 %r |
| 95 | } |
| 96 | |
| 97 | ; and (icmp ne (and ?, X), 0), (icmp ne X, 0) --> icmp ne (and ?, X), 0 |
| 98 | |
| 99 | define <3 x i1> @and_cmps_eq_zero_with_mask_commute3(<3 x i64> %x, <3 x i64> %y) { |
| 100 | ; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute3( |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 101 | ; CHECK-NEXT: [[SOMEBITS:%.*]] = and <3 x i64> %y, %x |
| 102 | ; CHECK-NEXT: [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne <3 x i64> [[SOMEBITS]], zeroinitializer |
Sanjay Patel | 6ef6aa9 | 2018-01-11 23:27:37 +0000 | [diff] [blame] | 103 | ; CHECK-NEXT: ret <3 x i1> [[SOMEBITS_ARE_NOT_ZERO]] |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 104 | ; |
| 105 | %isnotnull = icmp ne <3 x i64> %x, zeroinitializer |
| 106 | %somebits = and <3 x i64> %y, %x |
| 107 | %somebits_are_not_zero = icmp ne <3 x i64> %somebits, zeroinitializer |
| 108 | %r = and <3 x i1> %somebits_are_not_zero, %isnotnull |
| 109 | ret <3 x i1> %r |
| 110 | } |
| 111 | |
| 112 | ; and (icmp ne X, 0), (icmp ne (and ?, X), 0) --> icmp ne (and ?, X), 0 |
| 113 | |
| 114 | define i1 @and_cmps_eq_zero_with_mask_commute4(i64 %x, i64 %y) { |
| 115 | ; CHECK-LABEL: @and_cmps_eq_zero_with_mask_commute4( |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 116 | ; CHECK-NEXT: [[SOMEBITS:%.*]] = and i64 %y, %x |
| 117 | ; CHECK-NEXT: [[SOMEBITS_ARE_NOT_ZERO:%.*]] = icmp ne i64 [[SOMEBITS]], 0 |
Sanjay Patel | 6ef6aa9 | 2018-01-11 23:27:37 +0000 | [diff] [blame] | 118 | ; CHECK-NEXT: ret i1 [[SOMEBITS_ARE_NOT_ZERO]] |
Sanjay Patel | ac0edcb | 2018-01-11 22:48:07 +0000 | [diff] [blame] | 119 | ; |
| 120 | %isnotnull = icmp ne i64 %x, 0 |
| 121 | %somebits = and i64 %y, %x |
| 122 | %somebits_are_not_zero = icmp ne i64 %somebits, 0 |
| 123 | %r = and i1 %isnotnull, %somebits_are_not_zero |
| 124 | ret i1 %r |
| 125 | } |
| 126 | |