| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | 
| Duncan Sands | ba286d7 | 2011-10-26 20:55:21 +0000 | [diff] [blame] | 2 | ; RUN: opt < %s -instsimplify -S | FileCheck %s | 
|  | 3 |  | 
| Sanjay Patel | 308eb22 | 2017-02-18 21:51:14 +0000 | [diff] [blame] | 4 | ; add nsw (xor X, signbit), signbit --> X | 
|  | 5 |  | 
|  | 6 | define <2 x i32> @add_nsw_signbit(<2 x i32> %x) { | 
|  | 7 | ; CHECK-LABEL: @add_nsw_signbit( | 
| Sanjay Patel | fe67255 | 2017-02-18 21:59:09 +0000 | [diff] [blame] | 8 | ; CHECK-NEXT:    ret <2 x i32> %x | 
| Sanjay Patel | 308eb22 | 2017-02-18 21:51:14 +0000 | [diff] [blame] | 9 | ; | 
|  | 10 | %y = xor <2 x i32> %x, <i32 -2147483648, i32 -2147483648> | 
|  | 11 | %z = add nsw <2 x i32> %y, <i32 -2147483648, i32 -2147483648> | 
|  | 12 | ret <2 x i32> %z | 
|  | 13 | } | 
|  | 14 |  | 
|  | 15 | ; add nuw (xor X, signbit), signbit --> X | 
|  | 16 |  | 
|  | 17 | define <2 x i5> @add_nuw_signbit(<2 x i5> %x) { | 
|  | 18 | ; CHECK-LABEL: @add_nuw_signbit( | 
| Sanjay Patel | fe67255 | 2017-02-18 21:59:09 +0000 | [diff] [blame] | 19 | ; CHECK-NEXT:    ret <2 x i5> %x | 
| Sanjay Patel | 308eb22 | 2017-02-18 21:51:14 +0000 | [diff] [blame] | 20 | ; | 
|  | 21 | %y = xor <2 x i5> %x, <i5 -16, i5 -16> | 
|  | 22 | %z = add nuw <2 x i5> %y, <i5 -16, i5 -16> | 
|  | 23 | ret <2 x i5> %z | 
|  | 24 | } | 
|  | 25 |  | 
| Duncan Sands | ba286d7 | 2011-10-26 20:55:21 +0000 | [diff] [blame] | 26 | define i64 @pow2(i32 %x) { | 
| Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 27 | ; CHECK-LABEL: @pow2( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 28 | ; CHECK-NEXT:    [[NEGX:%.*]] = sub i32 0, %x | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 29 | ; CHECK-NEXT:    [[X2:%.*]] = and i32 %x, [[NEGX]] | 
|  | 30 | ; CHECK-NEXT:    [[E:%.*]] = zext i32 [[X2]] to i64 | 
|  | 31 | ; CHECK-NEXT:    ret i64 [[E]] | 
|  | 32 | ; | 
| Duncan Sands | ba286d7 | 2011-10-26 20:55:21 +0000 | [diff] [blame] | 33 | %negx = sub i32 0, %x | 
|  | 34 | %x2 = and i32 %x, %negx | 
|  | 35 | %e = zext i32 %x2 to i64 | 
|  | 36 | %nege = sub i64 0, %e | 
|  | 37 | %e2 = and i64 %e, %nege | 
|  | 38 | ret i64 %e2 | 
| Duncan Sands | ba286d7 | 2011-10-26 20:55:21 +0000 | [diff] [blame] | 39 | } | 
| Duncan Sands | 985ba63 | 2011-10-28 18:30:05 +0000 | [diff] [blame] | 40 |  | 
|  | 41 | define i64 @pow2b(i32 %x) { | 
| Stephen Lin | c1c7a13 | 2013-07-14 01:42:54 +0000 | [diff] [blame] | 42 | ; CHECK-LABEL: @pow2b( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 43 | ; CHECK-NEXT:    [[SH:%.*]] = shl i32 2, %x | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 44 | ; CHECK-NEXT:    [[E:%.*]] = zext i32 [[SH]] to i64 | 
|  | 45 | ; CHECK-NEXT:    ret i64 [[E]] | 
|  | 46 | ; | 
| Duncan Sands | 985ba63 | 2011-10-28 18:30:05 +0000 | [diff] [blame] | 47 | %sh = shl i32 2, %x | 
|  | 48 | %e = zext i32 %sh to i64 | 
|  | 49 | %nege = sub i64 0, %e | 
|  | 50 | %e2 = and i64 %e, %nege | 
|  | 51 | ret i64 %e2 | 
| Duncan Sands | 985ba63 | 2011-10-28 18:30:05 +0000 | [diff] [blame] | 52 | } | 
| David Majnemer | cd4fbcd | 2014-07-31 04:49:18 +0000 | [diff] [blame] | 53 |  | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 54 | define i1 @and_of_icmps0(i32 %b) { | 
|  | 55 | ; CHECK-LABEL: @and_of_icmps0( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 56 | ; CHECK-NEXT:    ret i1 false | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 57 | ; | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 58 | %1 = add i32 %b, 2 | 
|  | 59 | %2 = icmp ult i32 %1, 4 | 
|  | 60 | %cmp3 = icmp sgt i32 %b, 2 | 
|  | 61 | %cmp = and i1 %2, %cmp3 | 
|  | 62 | ret i1 %cmp | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 63 | } | 
|  | 64 |  | 
| Sanjay Patel | 1b312ad | 2016-09-28 13:53:13 +0000 | [diff] [blame] | 65 | define <2 x i1> @and_of_icmps0_vec(<2 x i32> %b) { | 
|  | 66 | ; CHECK-LABEL: @and_of_icmps0_vec( | 
|  | 67 | ; CHECK-NEXT:    ret <2 x i1> zeroinitializer | 
|  | 68 | ; | 
|  | 69 | %1 = add <2 x i32> %b, <i32 2, i32 2> | 
|  | 70 | %2 = icmp ult <2 x i32> %1, <i32 4, i32 4> | 
|  | 71 | %cmp3 = icmp sgt <2 x i32> %b, <i32 2, i32 2> | 
|  | 72 | %cmp = and <2 x i1> %2, %cmp3 | 
|  | 73 | ret <2 x i1> %cmp | 
|  | 74 | } | 
|  | 75 |  | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 76 | define i1 @and_of_icmps1(i32 %b) { | 
|  | 77 | ; CHECK-LABEL: @and_of_icmps1( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 78 | ; CHECK-NEXT:    ret i1 false | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 79 | ; | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 80 | %1 = add nsw i32 %b, 2 | 
|  | 81 | %2 = icmp slt i32 %1, 4 | 
|  | 82 | %cmp3 = icmp sgt i32 %b, 2 | 
|  | 83 | %cmp = and i1 %2, %cmp3 | 
|  | 84 | ret i1 %cmp | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 85 | } | 
|  | 86 |  | 
| Sanjay Patel | 1b312ad | 2016-09-28 13:53:13 +0000 | [diff] [blame] | 87 | define <2 x i1> @and_of_icmps1_vec(<2 x i32> %b) { | 
|  | 88 | ; CHECK-LABEL: @and_of_icmps1_vec( | 
|  | 89 | ; CHECK-NEXT:    ret <2 x i1> zeroinitializer | 
|  | 90 | ; | 
|  | 91 | %1 = add nsw <2 x i32> %b, <i32 2, i32 2> | 
|  | 92 | %2 = icmp slt <2 x i32> %1, <i32 4, i32 4> | 
|  | 93 | %cmp3 = icmp sgt <2 x i32> %b, <i32 2, i32 2> | 
|  | 94 | %cmp = and <2 x i1> %2, %cmp3 | 
|  | 95 | ret <2 x i1> %cmp | 
|  | 96 | } | 
|  | 97 |  | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 98 | define i1 @and_of_icmps2(i32 %b) { | 
|  | 99 | ; CHECK-LABEL: @and_of_icmps2( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 100 | ; CHECK-NEXT:    ret i1 false | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 101 | ; | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 102 | %1 = add i32 %b, 2 | 
|  | 103 | %2 = icmp ule i32 %1, 3 | 
|  | 104 | %cmp3 = icmp sgt i32 %b, 2 | 
|  | 105 | %cmp = and i1 %2, %cmp3 | 
|  | 106 | ret i1 %cmp | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 107 | } | 
|  | 108 |  | 
| Sanjay Patel | 1b312ad | 2016-09-28 13:53:13 +0000 | [diff] [blame] | 109 | define <2 x i1> @and_of_icmps2_vec(<2 x i32> %b) { | 
|  | 110 | ; CHECK-LABEL: @and_of_icmps2_vec( | 
|  | 111 | ; CHECK-NEXT:    ret <2 x i1> zeroinitializer | 
|  | 112 | ; | 
|  | 113 | %1 = add <2 x i32> %b, <i32 2, i32 2> | 
|  | 114 | %2 = icmp ule <2 x i32> %1, <i32 3, i32 3> | 
|  | 115 | %cmp3 = icmp sgt <2 x i32> %b, <i32 2, i32 2> | 
|  | 116 | %cmp = and <2 x i1> %2, %cmp3 | 
|  | 117 | ret <2 x i1> %cmp | 
|  | 118 | } | 
|  | 119 |  | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 120 | define i1 @and_of_icmps3(i32 %b) { | 
|  | 121 | ; CHECK-LABEL: @and_of_icmps3( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 122 | ; CHECK-NEXT:    ret i1 false | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 123 | ; | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 124 | %1 = add nsw i32 %b, 2 | 
|  | 125 | %2 = icmp sle i32 %1, 3 | 
|  | 126 | %cmp3 = icmp sgt i32 %b, 2 | 
|  | 127 | %cmp = and i1 %2, %cmp3 | 
|  | 128 | ret i1 %cmp | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 129 | } | 
|  | 130 |  | 
| Sanjay Patel | 1b312ad | 2016-09-28 13:53:13 +0000 | [diff] [blame] | 131 | define <2 x i1> @and_of_icmps3_vec(<2 x i32> %b) { | 
|  | 132 | ; CHECK-LABEL: @and_of_icmps3_vec( | 
|  | 133 | ; CHECK-NEXT:    ret <2 x i1> zeroinitializer | 
|  | 134 | ; | 
|  | 135 | %1 = add nsw <2 x i32> %b, <i32 2, i32 2> | 
|  | 136 | %2 = icmp sle <2 x i32> %1, <i32 3, i32 3> | 
|  | 137 | %cmp3 = icmp sgt <2 x i32> %b, <i32 2, i32 2> | 
|  | 138 | %cmp = and <2 x i1> %2, %cmp3 | 
|  | 139 | ret <2 x i1> %cmp | 
|  | 140 | } | 
|  | 141 |  | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 142 | define i1 @and_of_icmps4(i32 %b) { | 
|  | 143 | ; CHECK-LABEL: @and_of_icmps4( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 144 | ; CHECK-NEXT:    ret i1 false | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 145 | ; | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 146 | %1 = add nuw i32 %b, 2 | 
|  | 147 | %2 = icmp ult i32 %1, 4 | 
|  | 148 | %cmp3 = icmp ugt i32 %b, 2 | 
|  | 149 | %cmp = and i1 %2, %cmp3 | 
|  | 150 | ret i1 %cmp | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 151 | } | 
|  | 152 |  | 
| Sanjay Patel | 1b312ad | 2016-09-28 13:53:13 +0000 | [diff] [blame] | 153 | define <2 x i1> @and_of_icmps4_vec(<2 x i32> %b) { | 
|  | 154 | ; CHECK-LABEL: @and_of_icmps4_vec( | 
|  | 155 | ; CHECK-NEXT:    ret <2 x i1> zeroinitializer | 
|  | 156 | ; | 
|  | 157 | %1 = add nuw <2 x i32> %b, <i32 2, i32 2> | 
|  | 158 | %2 = icmp ult <2 x i32> %1, <i32 4, i32 4> | 
|  | 159 | %cmp3 = icmp ugt <2 x i32> %b, <i32 2, i32 2> | 
|  | 160 | %cmp = and <2 x i1> %2, %cmp3 | 
|  | 161 | ret <2 x i1> %cmp | 
|  | 162 | } | 
|  | 163 |  | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 164 | define i1 @and_of_icmps5(i32 %b) { | 
|  | 165 | ; CHECK-LABEL: @and_of_icmps5( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 166 | ; CHECK-NEXT:    ret i1 false | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 167 | ; | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 168 | %1 = add nuw i32 %b, 2 | 
|  | 169 | %2 = icmp ule i32 %1, 3 | 
|  | 170 | %cmp3 = icmp ugt i32 %b, 2 | 
|  | 171 | %cmp = and i1 %2, %cmp3 | 
|  | 172 | ret i1 %cmp | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 173 | } | 
|  | 174 |  | 
| Sanjay Patel | 1b312ad | 2016-09-28 13:53:13 +0000 | [diff] [blame] | 175 | define <2 x i1> @and_of_icmps5_vec(<2 x i32> %b) { | 
|  | 176 | ; CHECK-LABEL: @and_of_icmps5_vec( | 
|  | 177 | ; CHECK-NEXT:    ret <2 x i1> zeroinitializer | 
|  | 178 | ; | 
|  | 179 | %1 = add nuw <2 x i32> %b, <i32 2, i32 2> | 
|  | 180 | %2 = icmp ule <2 x i32> %1, <i32 3, i32 3> | 
|  | 181 | %cmp3 = icmp ugt <2 x i32> %b, <i32 2, i32 2> | 
|  | 182 | %cmp = and <2 x i1> %2, %cmp3 | 
|  | 183 | ret <2 x i1> %cmp | 
|  | 184 | } | 
|  | 185 |  | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 186 | define i1 @or_of_icmps0(i32 %b) { | 
|  | 187 | ; CHECK-LABEL: @or_of_icmps0( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 188 | ; CHECK-NEXT:    ret i1 true | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 189 | ; | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 190 | %1 = add i32 %b, 2 | 
|  | 191 | %2 = icmp uge i32 %1, 4 | 
|  | 192 | %cmp3 = icmp sle i32 %b, 2 | 
|  | 193 | %cmp = or i1 %2, %cmp3 | 
|  | 194 | ret i1 %cmp | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 195 | } | 
|  | 196 |  | 
| Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 197 | define <2 x i1> @or_of_icmps0_vec(<2 x i32> %b) { | 
|  | 198 | ; CHECK-LABEL: @or_of_icmps0_vec( | 
| Sanjay Patel | 220a873 | 2016-09-28 14:27:21 +0000 | [diff] [blame] | 199 | ; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true> | 
| Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 200 | ; | 
|  | 201 | %1 = add <2 x i32> %b, <i32 2, i32 2> | 
|  | 202 | %2 = icmp uge <2 x i32> %1, <i32 4, i32 4> | 
|  | 203 | %cmp3 = icmp sle <2 x i32> %b, <i32 2, i32 2> | 
|  | 204 | %cmp = or <2 x i1> %2, %cmp3 | 
|  | 205 | ret <2 x i1> %cmp | 
|  | 206 | } | 
|  | 207 |  | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 208 | define i1 @or_of_icmps1(i32 %b) { | 
|  | 209 | ; CHECK-LABEL: @or_of_icmps1( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 210 | ; CHECK-NEXT:    ret i1 true | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 211 | ; | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 212 | %1 = add nsw i32 %b, 2 | 
|  | 213 | %2 = icmp sge i32 %1, 4 | 
|  | 214 | %cmp3 = icmp sle i32 %b, 2 | 
|  | 215 | %cmp = or i1 %2, %cmp3 | 
|  | 216 | ret i1 %cmp | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 217 | } | 
|  | 218 |  | 
| Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 219 | define <2 x i1> @or_of_icmps1_vec(<2 x i32> %b) { | 
|  | 220 | ; CHECK-LABEL: @or_of_icmps1_vec( | 
| Sanjay Patel | 220a873 | 2016-09-28 14:27:21 +0000 | [diff] [blame] | 221 | ; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true> | 
| Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 222 | ; | 
|  | 223 | %1 = add nsw <2 x i32> %b, <i32 2, i32 2> | 
|  | 224 | %2 = icmp sge <2 x i32> %1, <i32 4, i32 4> | 
|  | 225 | %cmp3 = icmp sle <2 x i32> %b, <i32 2, i32 2> | 
|  | 226 | %cmp = or <2 x i1> %2, %cmp3 | 
|  | 227 | ret <2 x i1> %cmp | 
|  | 228 | } | 
|  | 229 |  | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 230 | define i1 @or_of_icmps2(i32 %b) { | 
|  | 231 | ; CHECK-LABEL: @or_of_icmps2( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 232 | ; CHECK-NEXT:    ret i1 true | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 233 | ; | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 234 | %1 = add i32 %b, 2 | 
|  | 235 | %2 = icmp ugt i32 %1, 3 | 
|  | 236 | %cmp3 = icmp sle i32 %b, 2 | 
|  | 237 | %cmp = or i1 %2, %cmp3 | 
|  | 238 | ret i1 %cmp | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 239 | } | 
|  | 240 |  | 
| Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 241 | define <2 x i1> @or_of_icmps2_vec(<2 x i32> %b) { | 
|  | 242 | ; CHECK-LABEL: @or_of_icmps2_vec( | 
| Sanjay Patel | 220a873 | 2016-09-28 14:27:21 +0000 | [diff] [blame] | 243 | ; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true> | 
| Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 244 | ; | 
|  | 245 | %1 = add <2 x i32> %b, <i32 2, i32 2> | 
|  | 246 | %2 = icmp ugt <2 x i32> %1, <i32 3, i32 3> | 
|  | 247 | %cmp3 = icmp sle <2 x i32> %b, <i32 2, i32 2> | 
|  | 248 | %cmp = or <2 x i1> %2, %cmp3 | 
|  | 249 | ret <2 x i1> %cmp | 
|  | 250 | } | 
|  | 251 |  | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 252 | define i1 @or_of_icmps3(i32 %b) { | 
|  | 253 | ; CHECK-LABEL: @or_of_icmps3( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 254 | ; CHECK-NEXT:    ret i1 true | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 255 | ; | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 256 | %1 = add nsw i32 %b, 2 | 
|  | 257 | %2 = icmp sgt i32 %1, 3 | 
|  | 258 | %cmp3 = icmp sle i32 %b, 2 | 
|  | 259 | %cmp = or i1 %2, %cmp3 | 
|  | 260 | ret i1 %cmp | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 261 | } | 
|  | 262 |  | 
| Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 263 | define <2 x i1> @or_of_icmps3_vec(<2 x i32> %b) { | 
|  | 264 | ; CHECK-LABEL: @or_of_icmps3_vec( | 
| Sanjay Patel | 220a873 | 2016-09-28 14:27:21 +0000 | [diff] [blame] | 265 | ; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true> | 
| Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 266 | ; | 
|  | 267 | %1 = add nsw <2 x i32> %b, <i32 2, i32 2> | 
|  | 268 | %2 = icmp sgt <2 x i32> %1, <i32 3, i32 3> | 
|  | 269 | %cmp3 = icmp sle <2 x i32> %b, <i32 2, i32 2> | 
|  | 270 | %cmp = or <2 x i1> %2, %cmp3 | 
|  | 271 | ret <2 x i1> %cmp | 
|  | 272 | } | 
|  | 273 |  | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 274 | define i1 @or_of_icmps4(i32 %b) { | 
|  | 275 | ; CHECK-LABEL: @or_of_icmps4( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 276 | ; CHECK-NEXT:    ret i1 true | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 277 | ; | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 278 | %1 = add nuw i32 %b, 2 | 
|  | 279 | %2 = icmp uge i32 %1, 4 | 
|  | 280 | %cmp3 = icmp ule i32 %b, 2 | 
|  | 281 | %cmp = or i1 %2, %cmp3 | 
|  | 282 | ret i1 %cmp | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 283 | } | 
|  | 284 |  | 
| Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 285 | define <2 x i1> @or_of_icmps4_vec(<2 x i32> %b) { | 
|  | 286 | ; CHECK-LABEL: @or_of_icmps4_vec( | 
| Sanjay Patel | 220a873 | 2016-09-28 14:27:21 +0000 | [diff] [blame] | 287 | ; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true> | 
| Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 288 | ; | 
|  | 289 | %1 = add nuw <2 x i32> %b, <i32 2, i32 2> | 
|  | 290 | %2 = icmp uge <2 x i32> %1, <i32 4, i32 4> | 
|  | 291 | %cmp3 = icmp ule <2 x i32> %b, <i32 2, i32 2> | 
|  | 292 | %cmp = or <2 x i1> %2, %cmp3 | 
|  | 293 | ret <2 x i1> %cmp | 
|  | 294 | } | 
|  | 295 |  | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 296 | define i1 @or_of_icmps5(i32 %b) { | 
|  | 297 | ; CHECK-LABEL: @or_of_icmps5( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 298 | ; CHECK-NEXT:    ret i1 true | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 299 | ; | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 300 | %1 = add nuw i32 %b, 2 | 
|  | 301 | %2 = icmp ugt i32 %1, 3 | 
|  | 302 | %cmp3 = icmp ule i32 %b, 2 | 
|  | 303 | %cmp = or i1 %2, %cmp3 | 
|  | 304 | ret i1 %cmp | 
| David Majnemer | a315bd8 | 2014-09-15 08:15:28 +0000 | [diff] [blame] | 305 | } | 
| David Majnemer | 4efa9ff | 2014-11-22 07:15:16 +0000 | [diff] [blame] | 306 |  | 
| Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 307 | define <2 x i1> @or_of_icmps5_vec(<2 x i32> %b) { | 
|  | 308 | ; CHECK-LABEL: @or_of_icmps5_vec( | 
| Sanjay Patel | 220a873 | 2016-09-28 14:27:21 +0000 | [diff] [blame] | 309 | ; CHECK-NEXT:    ret <2 x i1> <i1 true, i1 true> | 
| Sanjay Patel | a8f9e57 | 2016-09-28 14:17:35 +0000 | [diff] [blame] | 310 | ; | 
|  | 311 | %1 = add nuw <2 x i32> %b, <i32 2, i32 2> | 
|  | 312 | %2 = icmp ugt <2 x i32> %1, <i32 3, i32 3> | 
|  | 313 | %cmp3 = icmp ule <2 x i32> %b, <i32 2, i32 2> | 
|  | 314 | %cmp = or <2 x i1> %2, %cmp3 | 
|  | 315 | ret <2 x i1> %cmp | 
|  | 316 | } | 
|  | 317 |  | 
| David Majnemer | 4efa9ff | 2014-11-22 07:15:16 +0000 | [diff] [blame] | 318 | define i32 @neg_nuw(i32 %x) { | 
|  | 319 | ; CHECK-LABEL: @neg_nuw( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 320 | ; CHECK-NEXT:    ret i32 0 | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 321 | ; | 
| David Majnemer | 4efa9ff | 2014-11-22 07:15:16 +0000 | [diff] [blame] | 322 | %neg = sub nuw i32 0, %x | 
|  | 323 | ret i32 %neg | 
| David Majnemer | 4efa9ff | 2014-11-22 07:15:16 +0000 | [diff] [blame] | 324 | } | 
| David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 325 |  | 
|  | 326 | define i1 @and_icmp1(i32 %x, i32 %y) { | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 327 | ; CHECK-LABEL: @and_icmp1( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 328 | ; CHECK-NEXT:    [[TMP1:%.*]] = icmp ult i32 %x, %y | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 329 | ; CHECK-NEXT:    ret i1 [[TMP1]] | 
|  | 330 | ; | 
| David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 331 | %1 = icmp ult i32 %x, %y | 
|  | 332 | %2 = icmp ne i32 %y, 0 | 
|  | 333 | %3 = and i1 %1, %2 | 
|  | 334 | ret i1 %3 | 
|  | 335 | } | 
| David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 336 |  | 
| David Majnemer | d5b3aa4 | 2014-12-08 18:30:43 +0000 | [diff] [blame] | 337 | define i1 @and_icmp2(i32 %x, i32 %y) { | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 338 | ; CHECK-LABEL: @and_icmp2( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 339 | ; CHECK-NEXT:    ret i1 false | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 340 | ; | 
| David Majnemer | d5b3aa4 | 2014-12-08 18:30:43 +0000 | [diff] [blame] | 341 | %1 = icmp ult i32 %x, %y | 
|  | 342 | %2 = icmp eq i32 %y, 0 | 
|  | 343 | %3 = and i1 %1, %2 | 
|  | 344 | ret i1 %3 | 
|  | 345 | } | 
| David Majnemer | d5b3aa4 | 2014-12-08 18:30:43 +0000 | [diff] [blame] | 346 |  | 
| David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 347 | define i1 @or_icmp1(i32 %x, i32 %y) { | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 348 | ; CHECK-LABEL: @or_icmp1( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 349 | ; CHECK-NEXT:    [[TMP1:%.*]] = icmp ne i32 %y, 0 | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 350 | ; CHECK-NEXT:    ret i1 [[TMP1]] | 
|  | 351 | ; | 
| David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 352 | %1 = icmp ult i32 %x, %y | 
|  | 353 | %2 = icmp ne i32 %y, 0 | 
|  | 354 | %3 = or i1 %1, %2 | 
|  | 355 | ret i1 %3 | 
|  | 356 | } | 
| David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 357 |  | 
|  | 358 | define i1 @or_icmp2(i32 %x, i32 %y) { | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 359 | ; CHECK-LABEL: @or_icmp2( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 360 | ; CHECK-NEXT:    ret i1 true | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 361 | ; | 
| David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 362 | %1 = icmp uge i32 %x, %y | 
|  | 363 | %2 = icmp ne i32 %y, 0 | 
|  | 364 | %3 = or i1 %1, %2 | 
|  | 365 | ret i1 %3 | 
|  | 366 | } | 
| David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 367 |  | 
|  | 368 | define i1 @or_icmp3(i32 %x, i32 %y) { | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 369 | ; CHECK-LABEL: @or_icmp3( | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 370 | ; CHECK-NEXT:    [[TMP1:%.*]] = icmp uge i32 %x, %y | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 371 | ; CHECK-NEXT:    ret i1 [[TMP1]] | 
|  | 372 | ; | 
| David Majnemer | 1af36e5 | 2014-12-06 10:51:40 +0000 | [diff] [blame] | 373 | %1 = icmp uge i32 %x, %y | 
|  | 374 | %2 = icmp eq i32 %y, 0 | 
|  | 375 | %3 = or i1 %1, %2 | 
|  | 376 | ret i1 %3 | 
|  | 377 | } | 
| Sanjay Patel | 6963244 | 2016-03-25 20:12:25 +0000 | [diff] [blame] | 378 |  | 
| Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 379 | ; PR27869 - Look through casts to eliminate cmps and bitwise logic. | 
|  | 380 |  | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 381 | define i32 @and_of_zexted_icmps(i32 %i) { | 
|  | 382 | ; CHECK-LABEL: @and_of_zexted_icmps( | 
| Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 383 | ; CHECK-NEXT:    ret i32 0 | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 384 | ; | 
| Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 385 | %cmp0 = icmp eq i32 %i, 0 | 
|  | 386 | %conv0 = zext i1 %cmp0 to i32 | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 387 | %cmp1 = icmp ugt i32 %i, 4 | 
| Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 388 | %conv1 = zext i1 %cmp1 to i32 | 
|  | 389 | %and = and i32 %conv0, %conv1 | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 390 | ret i32 %and | 
|  | 391 | } | 
|  | 392 |  | 
| Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 393 | ; Make sure vectors work too. | 
|  | 394 |  | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 395 | define <4 x i32> @and_of_zexted_icmps_vec(<4 x i32> %i) { | 
|  | 396 | ; CHECK-LABEL: @and_of_zexted_icmps_vec( | 
| Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 397 | ; CHECK-NEXT:    ret <4 x i32> zeroinitializer | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 398 | ; | 
| Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 399 | %cmp0 = icmp eq <4 x i32> %i, zeroinitializer | 
|  | 400 | %conv0 = zext <4 x i1> %cmp0 to <4 x i32> | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 401 | %cmp1 = icmp slt <4 x i32> %i, zeroinitializer | 
| Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 402 | %conv1 = zext <4 x i1> %cmp1 to <4 x i32> | 
|  | 403 | %and = and <4 x i32> %conv0, %conv1 | 
| Sanjay Patel | a4b052c | 2016-06-19 21:40:12 +0000 | [diff] [blame] | 404 | ret <4 x i32> %and | 
|  | 405 | } | 
|  | 406 |  | 
| Sanjay Patel | 9ad8fb6 | 2016-06-20 20:59:59 +0000 | [diff] [blame] | 407 | ; Try a different cast and weird types. | 
|  | 408 |  | 
|  | 409 | define i5 @and_of_sexted_icmps(i3 %i) { | 
|  | 410 | ; CHECK-LABEL: @and_of_sexted_icmps( | 
|  | 411 | ; CHECK-NEXT:    ret i5 0 | 
|  | 412 | ; | 
|  | 413 | %cmp0 = icmp eq i3 %i, 0 | 
|  | 414 | %conv0 = sext i1 %cmp0 to i5 | 
|  | 415 | %cmp1 = icmp ugt i3 %i, 1 | 
|  | 416 | %conv1 = sext i1 %cmp1 to i5 | 
|  | 417 | %and = and i5 %conv0, %conv1 | 
|  | 418 | ret i5 %and | 
|  | 419 | } | 
|  | 420 |  | 
|  | 421 | ; Try a different cast and weird vector types. | 
|  | 422 |  | 
|  | 423 | define i3 @and_of_bitcast_icmps_vec(<3 x i65> %i) { | 
|  | 424 | ; CHECK-LABEL: @and_of_bitcast_icmps_vec( | 
|  | 425 | ; CHECK-NEXT:    ret i3 0 | 
|  | 426 | ; | 
|  | 427 | %cmp0 = icmp sgt <3 x i65> %i, zeroinitializer | 
|  | 428 | %conv0 = bitcast <3 x i1> %cmp0 to i3 | 
|  | 429 | %cmp1 = icmp slt <3 x i65> %i, zeroinitializer | 
|  | 430 | %conv1 = bitcast <3 x i1> %cmp1 to i3 | 
|  | 431 | %and = and i3 %conv0, %conv1 | 
|  | 432 | ret i3 %and | 
|  | 433 | } | 
|  | 434 |  | 
|  | 435 | ; We can't do this if the casts are different. | 
|  | 436 |  | 
|  | 437 | define i16 @and_of_different_cast_icmps(i8 %i) { | 
|  | 438 | ; CHECK-LABEL: @and_of_different_cast_icmps( | 
|  | 439 | ; CHECK-NEXT:    [[CMP0:%.*]] = icmp eq i8 %i, 0 | 
|  | 440 | ; CHECK-NEXT:    [[CONV0:%.*]] = zext i1 [[CMP0]] to i16 | 
|  | 441 | ; CHECK-NEXT:    [[CMP1:%.*]] = icmp eq i8 %i, 1 | 
|  | 442 | ; CHECK-NEXT:    [[CONV1:%.*]] = sext i1 [[CMP1]] to i16 | 
|  | 443 | ; CHECK-NEXT:    [[AND:%.*]] = and i16 [[CONV0]], [[CONV1]] | 
|  | 444 | ; CHECK-NEXT:    ret i16 [[AND]] | 
|  | 445 | ; | 
|  | 446 | %cmp0 = icmp eq i8 %i, 0 | 
|  | 447 | %conv0 = zext i1 %cmp0 to i16 | 
|  | 448 | %cmp1 = icmp eq i8 %i, 1 | 
|  | 449 | %conv1 = sext i1 %cmp1 to i16 | 
|  | 450 | %and = and i16 %conv0, %conv1 | 
|  | 451 | ret i16 %and | 
|  | 452 | } | 
|  | 453 |  | 
|  | 454 | define <2 x i3> @and_of_different_cast_icmps_vec(<2 x i8> %i, <2 x i16> %j) { | 
|  | 455 | ; CHECK-LABEL: @and_of_different_cast_icmps_vec( | 
|  | 456 | ; CHECK-NEXT:    [[CMP0:%.*]] = icmp eq <2 x i8> %i, zeroinitializer | 
|  | 457 | ; CHECK-NEXT:    [[CONV0:%.*]] = zext <2 x i1> [[CMP0]] to <2 x i3> | 
|  | 458 | ; CHECK-NEXT:    [[CMP1:%.*]] = icmp ugt <2 x i16> %j, <i16 1, i16 1> | 
|  | 459 | ; CHECK-NEXT:    [[CONV1:%.*]] = zext <2 x i1> [[CMP1]] to <2 x i3> | 
|  | 460 | ; CHECK-NEXT:    [[AND:%.*]] = and <2 x i3> [[CONV0]], [[CONV1]] | 
|  | 461 | ; CHECK-NEXT:    ret <2 x i3> [[AND]] | 
|  | 462 | ; | 
|  | 463 | %cmp0 = icmp eq <2 x i8> %i, zeroinitializer | 
|  | 464 | %conv0 = zext <2 x i1> %cmp0 to <2 x i3> | 
|  | 465 | %cmp1 = icmp ugt <2 x i16> %j, <i16 1, i16 1> | 
|  | 466 | %conv1 = zext <2 x i1> %cmp1 to <2 x i3> | 
|  | 467 | %and = and <2 x i3> %conv0, %conv1 | 
|  | 468 | ret <2 x i3> %and | 
|  | 469 | } | 
|  | 470 |  | 
| Sanjay Patel | 0889225 | 2017-04-24 18:24:36 +0000 | [diff] [blame] | 471 | ; (A & ~B) | (A ^ B) -> A ^ B | 
|  | 472 |  | 
|  | 473 | define i32 @test43(i32 %a, i32 %b) { | 
|  | 474 | ; CHECK-LABEL: @test43( | 
|  | 475 | ; CHECK-NEXT:    [[OR:%.*]] = xor i32 %a, %b | 
|  | 476 | ; CHECK-NEXT:    ret i32 [[OR]] | 
|  | 477 | ; | 
|  | 478 | %neg = xor i32 %b, -1 | 
|  | 479 | %and = and i32 %a, %neg | 
|  | 480 | %xor = xor i32 %a, %b | 
|  | 481 | %or = or i32 %and, %xor | 
|  | 482 | ret i32 %or | 
|  | 483 | } | 
|  | 484 |  | 
|  | 485 | define i32 @test43_commuted_and(i32 %a, i32 %b) { | 
|  | 486 | ; CHECK-LABEL: @test43_commuted_and( | 
|  | 487 | ; CHECK-NEXT:    [[OR:%.*]] = xor i32 %a, %b | 
|  | 488 | ; CHECK-NEXT:    ret i32 [[OR]] | 
|  | 489 | ; | 
|  | 490 | %neg = xor i32 %b, -1 | 
|  | 491 | %and = and i32 %neg, %a | 
|  | 492 | %xor = xor i32 %a, %b | 
|  | 493 | %or = or i32 %and, %xor | 
|  | 494 | ret i32 %or | 
|  | 495 | } | 
|  | 496 |  | 
|  | 497 | ; Commute operands of the 'or'. | 
|  | 498 | ; (A ^ B) | (A & ~B) -> A ^ B | 
|  | 499 |  | 
|  | 500 | define i32 @test44(i32 %a, i32 %b) { | 
|  | 501 | ; CHECK-LABEL: @test44( | 
|  | 502 | ; CHECK-NEXT:    [[OR:%.*]] = xor i32 %a, %b | 
|  | 503 | ; CHECK-NEXT:    ret i32 [[OR]] | 
|  | 504 | ; | 
|  | 505 | %xor = xor i32 %a, %b | 
|  | 506 | %neg = xor i32 %b, -1 | 
|  | 507 | %and = and i32 %a, %neg | 
|  | 508 | %or = or i32 %xor, %and | 
|  | 509 | ret i32 %or | 
|  | 510 | } | 
|  | 511 |  | 
|  | 512 | define i32 @test44_commuted_and(i32 %a, i32 %b) { | 
|  | 513 | ; CHECK-LABEL: @test44_commuted_and( | 
|  | 514 | ; CHECK-NEXT:    [[OR:%.*]] = xor i32 %a, %b | 
|  | 515 | ; CHECK-NEXT:    ret i32 [[OR]] | 
|  | 516 | ; | 
|  | 517 | %xor = xor i32 %a, %b | 
|  | 518 | %neg = xor i32 %b, -1 | 
|  | 519 | %and = and i32 %neg, %a | 
|  | 520 | %or = or i32 %xor, %and | 
|  | 521 | ret i32 %or | 
|  | 522 | } | 
|  | 523 |  | 
| Craig Topper | 0b650d3 | 2017-04-25 17:01:32 +0000 | [diff] [blame^] | 524 | ; (~A & ~B) | (~A ^ B) -> ~A ^ B | 
|  | 525 |  | 
|  | 526 | define i32 @test45(i32 %a, i32 %b) { | 
|  | 527 | ; CHECK-LABEL: @test45( | 
|  | 528 | ; CHECK-NEXT:    [[NEGB:%.*]] = xor i32 [[B:%.*]], -1 | 
|  | 529 | ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[A:%.*]], [[NEGB]] | 
|  | 530 | ; CHECK-NEXT:    ret i32 [[XOR]] | 
|  | 531 | ; | 
|  | 532 | %nega = xor i32 %a, -1 | 
|  | 533 | %negb = xor i32 %b, -1 | 
|  | 534 | %and = and i32 %nega, %negb | 
|  | 535 | %xor = xor i32 %a, %negb | 
|  | 536 | %or = or i32 %and, %xor | 
|  | 537 | ret i32 %or | 
|  | 538 | } | 
|  | 539 |  | 
|  | 540 | define i32 @test45_commuted_and(i32 %a, i32 %b) { | 
|  | 541 | ; CHECK-LABEL: @test45( | 
|  | 542 | ; CHECK-NEXT:    [[NEGB:%.*]] = xor i32 [[B:%.*]], -1 | 
|  | 543 | ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[A:%.*]], [[NEGB]] | 
|  | 544 | ; CHECK-NEXT:    ret i32 [[XOR]] | 
|  | 545 | ; | 
|  | 546 | %nega = xor i32 %a, -1 | 
|  | 547 | %negb = xor i32 %b, -1 | 
|  | 548 | %and = and i32 %negb, %nega | 
|  | 549 | %xor = xor i32 %a, %negb | 
|  | 550 | %or = or i32 %and, %xor | 
|  | 551 | ret i32 %or | 
|  | 552 | } | 
|  | 553 |  | 
|  | 554 | ; Commute operands of the 'or'. | 
|  | 555 | ; (~A ^ B) | (~A & ~B) -> ~A ^ B | 
|  | 556 |  | 
|  | 557 | define i32 @test46(i32 %a, i32 %b) { | 
|  | 558 | ; CHECK-LABEL: @test46( | 
|  | 559 | ; CHECK-NEXT:    [[NEGB:%.*]] = xor i32 [[B:%.*]], -1 | 
|  | 560 | ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[A:%.*]], [[NEGB]] | 
|  | 561 | ; CHECK-NEXT:    ret i32 [[XOR]] | 
|  | 562 | ; | 
|  | 563 | %nega = xor i32 %a, -1 | 
|  | 564 | %negb = xor i32 %b, -1 | 
|  | 565 | %and = and i32 %nega, %negb | 
|  | 566 | %xor = xor i32 %a, %negb | 
|  | 567 | %or = or i32 %xor, %and | 
|  | 568 | ret i32 %or | 
|  | 569 | } | 
|  | 570 |  | 
|  | 571 | ; (~A & ~B) | (~A ^ B) -> ~A ^ B | 
|  | 572 |  | 
|  | 573 | define i32 @test46_commuted_and(i32 %a, i32 %b) { | 
|  | 574 | ; CHECK-LABEL: @test45( | 
|  | 575 | ; CHECK-NEXT:    [[NEGB:%.*]] = xor i32 [[B:%.*]], -1 | 
|  | 576 | ; CHECK-NEXT:    [[XOR:%.*]] = xor i32 [[A:%.*]], [[NEGB]] | 
|  | 577 | ; CHECK-NEXT:    ret i32 [[XOR]] | 
|  | 578 | ; | 
|  | 579 | %nega = xor i32 %a, -1 | 
|  | 580 | %negb = xor i32 %b, -1 | 
|  | 581 | %and = and i32 %negb, %nega | 
|  | 582 | %xor = xor i32 %a, %negb | 
|  | 583 | %or = or i32 %xor, %and | 
|  | 584 | ret i32 %or | 
|  | 585 | } |