|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 |
| 2 | +; RUN: opt -S -passes=bdce < %s | FileCheck %s |
| 3 | + |
| 4 | +define void @or(i64 %a) { |
| 5 | +; CHECK-LABEL: define void @or( |
| 6 | +; CHECK-SAME: i64 [[A:%.*]]) { |
| 7 | +; CHECK-NEXT: entry: |
| 8 | +; CHECK-NEXT: [[OR:%.*]] = or i64 [[A]], 3 |
| 9 | +; CHECK-NEXT: [[RET1:%.*]] = and i64 [[OR]], 8 |
| 10 | +; CHECK-NEXT: [[RET2:%.*]] = and i64 [[OR]], 16 |
| 11 | +; CHECK-NEXT: call void @use(i64 [[RET1]]) |
| 12 | +; CHECK-NEXT: call void @use(i64 [[RET2]]) |
| 13 | +; CHECK-NEXT: ret void |
| 14 | +; |
| 15 | +entry: |
| 16 | + %or = or i64 %a, 3 ; Mask: 0000 0011 |
| 17 | + %ret1 = and i64 %or, 8 ; Demanded bits: 0000 1000 |
| 18 | + %ret2 = and i64 %or, 16 ; Demanded bits: 0001 0000 |
| 19 | + call void @use(i64 %ret1) |
| 20 | + call void @use(i64 %ret2) |
| 21 | + ret void |
| 22 | +} |
| 23 | + |
| 24 | +define void @xor(i64 %a) { |
| 25 | +; CHECK-LABEL: define void @xor( |
| 26 | +; CHECK-SAME: i64 [[A:%.*]]) { |
| 27 | +; CHECK-NEXT: entry: |
| 28 | +; CHECK-NEXT: [[XOR:%.*]] = xor i64 [[A]], 3 |
| 29 | +; CHECK-NEXT: [[RET1:%.*]] = and i64 [[XOR]], 8 |
| 30 | +; CHECK-NEXT: [[RET2:%.*]] = and i64 [[XOR]], 16 |
| 31 | +; CHECK-NEXT: call void @use(i64 [[RET1]]) |
| 32 | +; CHECK-NEXT: call void @use(i64 [[RET2]]) |
| 33 | +; CHECK-NEXT: ret void |
| 34 | +; |
| 35 | +entry: |
| 36 | + %xor = xor i64 %a, 3 ; Mask: 0000 0011 |
| 37 | + %ret1 = and i64 %xor, 8 ; Demanded bits: 0000 1000 |
| 38 | + %ret2 = and i64 %xor, 16 ; Demanded bits: 0001 0000 |
| 39 | + call void @use(i64 %ret1) |
| 40 | + call void @use(i64 %ret2) |
| 41 | + ret void |
| 42 | +} |
| 43 | + |
| 44 | +define void @and(i64 %a) { |
| 45 | +; CHECK-LABEL: define void @and( |
| 46 | +; CHECK-SAME: i64 [[A:%.*]]) { |
| 47 | +; CHECK-NEXT: entry: |
| 48 | +; CHECK-NEXT: [[AND:%.*]] = and i64 [[A]], 24 |
| 49 | +; CHECK-NEXT: [[RET1:%.*]] = and i64 [[AND]], 8 |
| 50 | +; CHECK-NEXT: [[RET2:%.*]] = and i64 [[AND]], 16 |
| 51 | +; CHECK-NEXT: call void @use(i64 [[RET1]]) |
| 52 | +; CHECK-NEXT: call void @use(i64 [[RET2]]) |
| 53 | +; CHECK-NEXT: ret void |
| 54 | +; |
| 55 | +entry: |
| 56 | + %and = and i64 %a, 24 ; Mask: 0001 1000 |
| 57 | + %ret1 = and i64 %and, 8 ; Demanded bits: 0000 1000 |
| 58 | + %ret2 = and i64 %and, 16 ; Demanded bits: 0001 0000 |
| 59 | + call void @use(i64 %ret1) |
| 60 | + call void @use(i64 %ret2) |
| 61 | + ret void |
| 62 | +} |
| 63 | + |
| 64 | +define void @or_of_and(i64 %a, i64 %b) { |
| 65 | +; CHECK-LABEL: define void @or_of_and( |
| 66 | +; CHECK-SAME: i64 [[A:%.*]], i64 [[B:%.*]]) { |
| 67 | +; CHECK-NEXT: entry: |
| 68 | +; CHECK-NEXT: [[AND1:%.*]] = and i64 [[A]], 24 |
| 69 | +; CHECK-NEXT: [[AND2:%.*]] = and i64 [[B]], 25 |
| 70 | +; CHECK-NEXT: [[OR:%.*]] = or i64 [[AND1]], [[AND2]] |
| 71 | +; CHECK-NEXT: [[RET1:%.*]] = and i64 [[OR]], 8 |
| 72 | +; CHECK-NEXT: [[RET2:%.*]] = and i64 [[OR]], 16 |
| 73 | +; CHECK-NEXT: call void @use(i64 [[RET1]]) |
| 74 | +; CHECK-NEXT: call void @use(i64 [[RET2]]) |
| 75 | +; CHECK-NEXT: ret void |
| 76 | +; |
| 77 | +entry: |
| 78 | + %and1 = and i64 %a, 24 ; Mask: 0001 1000 |
| 79 | + %and2 = and i64 %b, 25 ; Mask: 0001 1001 |
| 80 | + %or = or i64 %and1, %and2 |
| 81 | + %ret1 = and i64 %or, 8 ; Demanded bits: 0000 1000 |
| 82 | + %ret2 = and i64 %or, 16 ; Demanded bits: 0001 0000 |
| 83 | + call void @use(i64 %ret1) |
| 84 | + call void @use(i64 %ret2) |
| 85 | + ret void |
| 86 | +} |
| 87 | + |
| 88 | +define void @or_disjoint_of_and(i64 %a, i64 %b) { |
| 89 | +; CHECK-LABEL: define void @or_disjoint_of_and( |
| 90 | +; CHECK-SAME: i64 [[A:%.*]], i64 [[B:%.*]]) { |
| 91 | +; CHECK-NEXT: entry: |
| 92 | +; CHECK-NEXT: [[AND1:%.*]] = and i64 [[A]], 56 |
| 93 | +; CHECK-NEXT: [[AND2:%.*]] = and i64 [[B]], 25 |
| 94 | +; CHECK-NEXT: [[OR:%.*]] = or disjoint i64 [[AND1]], [[AND2]] |
| 95 | +; CHECK-NEXT: [[RET1:%.*]] = and i64 [[OR]], 8 |
| 96 | +; CHECK-NEXT: [[RET2:%.*]] = and i64 [[OR]], 16 |
| 97 | +; CHECK-NEXT: call void @use(i64 [[RET1]]) |
| 98 | +; CHECK-NEXT: call void @use(i64 [[RET2]]) |
| 99 | +; CHECK-NEXT: ret void |
| 100 | +; |
| 101 | +entry: |
| 102 | + %and1 = and i64 %a, 56 ; Mask: 0011 1000 |
| 103 | + %and2 = and i64 %b, 25 ; Mask: 0001 1001 |
| 104 | + %or = or disjoint i64 %and1, %and2 |
| 105 | + %ret1 = and i64 %or, 8 ; Demanded bits: 0000 1000 |
| 106 | + %ret2 = and i64 %or, 16 ; Demanded bits: 0001 0000 |
| 107 | + call void @use(i64 %ret1) |
| 108 | + call void @use(i64 %ret2) |
| 109 | + ret void |
| 110 | +} |
| 111 | + |
| 112 | +define void @select_of_and(i1 %c, i64 %a, i64 %b) { |
| 113 | +; CHECK-LABEL: define void @select_of_and( |
| 114 | +; CHECK-SAME: i1 [[C:%.*]], i64 [[A:%.*]], i64 [[B:%.*]]) { |
| 115 | +; CHECK-NEXT: entry: |
| 116 | +; CHECK-NEXT: [[AND1:%.*]] = and i64 [[A]], 24 |
| 117 | +; CHECK-NEXT: [[AND2:%.*]] = and i64 [[B]], 25 |
| 118 | +; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i64 [[AND1]], i64 [[AND2]] |
| 119 | +; CHECK-NEXT: [[RET1:%.*]] = and i64 [[S]], 8 |
| 120 | +; CHECK-NEXT: [[RET2:%.*]] = and i64 [[S]], 16 |
| 121 | +; CHECK-NEXT: call void @use(i64 [[RET1]]) |
| 122 | +; CHECK-NEXT: call void @use(i64 [[RET2]]) |
| 123 | +; CHECK-NEXT: ret void |
| 124 | +; |
| 125 | +entry: |
| 126 | + %and1 = and i64 %a, 24 ; Mask: 0001 1000 |
| 127 | + %and2 = and i64 %b, 25 ; Mask: 0001 1001 |
| 128 | + %s = select i1 %c, i64 %and1, i64 %and2 |
| 129 | + %ret1 = and i64 %s, 8 ; Demanded bits: 0000 1000 |
| 130 | + %ret2 = and i64 %s, 16 ; Demanded bits: 0001 0000 |
| 131 | + call void @use(i64 %ret1) |
| 132 | + call void @use(i64 %ret2) |
| 133 | + ret void |
| 134 | +} |
| 135 | + |
| 136 | +define void @select_of_and_2(i1 %c, i64 %a, i64 %b) { |
| 137 | +; CHECK-LABEL: define void @select_of_and_2( |
| 138 | +; CHECK-SAME: i1 [[C:%.*]], i64 [[A:%.*]], i64 [[B:%.*]]) { |
| 139 | +; CHECK-NEXT: entry: |
| 140 | +; CHECK-NEXT: [[AND1:%.*]] = and i64 [[A]], 25 |
| 141 | +; CHECK-NEXT: [[AND2:%.*]] = and i64 [[B]], 23 |
| 142 | +; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i64 [[AND1]], i64 [[AND2]] |
| 143 | +; CHECK-NEXT: [[RET1:%.*]] = and i64 [[S]], 8 |
| 144 | +; CHECK-NEXT: [[RET2:%.*]] = and i64 [[S]], 16 |
| 145 | +; CHECK-NEXT: call void @use(i64 [[RET1]]) |
| 146 | +; CHECK-NEXT: call void @use(i64 [[RET2]]) |
| 147 | +; CHECK-NEXT: ret void |
| 148 | +; |
| 149 | +entry: |
| 150 | + %and1 = and i64 %a, 25 ; Mask: 0001 1001 |
| 151 | + %and2 = and i64 %b, 23 ; Mask: 0001 0111 |
| 152 | + %s = select i1 %c, i64 %and1, i64 %and2 |
| 153 | + %ret1 = and i64 %s, 8 ; Demanded bits: 0000 1000 |
| 154 | + %ret2 = and i64 %s, 16 ; Demanded bits: 0001 0000 |
| 155 | + call void @use(i64 %ret1) |
| 156 | + call void @use(i64 %ret2) |
| 157 | + ret void |
| 158 | +} |
| 159 | + |
| 160 | +define void @select_of_and_multiuse(i1 %c, i64 %a, i64 %b) { |
| 161 | +; CHECK-LABEL: define void @select_of_and_multiuse( |
| 162 | +; CHECK-SAME: i1 [[C:%.*]], i64 [[A:%.*]], i64 [[B:%.*]]) { |
| 163 | +; CHECK-NEXT: entry: |
| 164 | +; CHECK-NEXT: [[AND1:%.*]] = and i64 [[A]], 24 |
| 165 | +; CHECK-NEXT: [[AND2:%.*]] = and i64 [[B]], 25 |
| 166 | +; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i64 [[AND1]], i64 [[AND2]] |
| 167 | +; CHECK-NEXT: [[RET1:%.*]] = and i64 [[S]], 8 |
| 168 | +; CHECK-NEXT: [[RET2:%.*]] = and i64 [[S]], 16 |
| 169 | +; CHECK-NEXT: call void @use(i64 [[RET1]]) |
| 170 | +; CHECK-NEXT: call void @use2(i64 [[RET2]], i64 [[AND2]]) |
| 171 | +; CHECK-NEXT: ret void |
| 172 | +; |
| 173 | +entry: |
| 174 | + %and1 = and i64 %a, 24 ; Mask: 0001 1000 |
| 175 | + %and2 = and i64 %b, 25 ; Mask: 0001 1001 |
| 176 | + %s = select i1 %c, i64 %and1, i64 %and2 |
| 177 | + %ret1 = and i64 %s, 8 ; Demanded bits: 0000 1000 |
| 178 | + %ret2 = and i64 %s, 16 ; Demanded bits: 0001 0000 |
| 179 | + call void @use(i64 %ret1) |
| 180 | + call void @use2(i64 %ret2, i64 %and2) |
| 181 | + ret void |
| 182 | +} |
| 183 | + |
| 184 | +define void @select_of_and_different_demanded(i1 %c, i64 %a, i64 %b) { |
| 185 | +; CHECK-LABEL: define void @select_of_and_different_demanded( |
| 186 | +; CHECK-SAME: i1 [[C:%.*]], i64 [[A:%.*]], i64 [[B:%.*]]) { |
| 187 | +; CHECK-NEXT: entry: |
| 188 | +; CHECK-NEXT: [[AND1:%.*]] = and i64 0, 24 |
| 189 | +; CHECK-NEXT: [[AND2:%.*]] = and i64 [[B]], 25 |
| 190 | +; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i64 [[AND1]], i64 [[AND2]] |
| 191 | +; CHECK-NEXT: [[RET1:%.*]] = and i64 [[S]], 3 |
| 192 | +; CHECK-NEXT: [[RET2:%.*]] = and i64 [[S]], 7 |
| 193 | +; CHECK-NEXT: call void @use(i64 [[RET1]]) |
| 194 | +; CHECK-NEXT: call void @use(i64 [[RET2]]) |
| 195 | +; CHECK-NEXT: ret void |
| 196 | +; |
| 197 | +entry: |
| 198 | + %and1 = and i64 %a, 24 ; Mask: 0001 1000 |
| 199 | + %and2 = and i64 %b, 25 ; Mask: 0001 1001 |
| 200 | + %s = select i1 %c, i64 %and1, i64 %and2 |
| 201 | + %ret1 = and i64 %s, 3 ; Demanded bits: 0000 0011 |
| 202 | + %ret2 = and i64 %s, 7 ; Demanded bits: 0000 0111 |
| 203 | + call void @use(i64 %ret1) |
| 204 | + call void @use(i64 %ret2) |
| 205 | + ret void |
| 206 | +} |
| 207 | + |
| 208 | +define void @select_of_or(i1 %c, i64 %a, i64 %b) { |
| 209 | +; CHECK-LABEL: define void @select_of_or( |
| 210 | +; CHECK-SAME: i1 [[C:%.*]], i64 [[A:%.*]], i64 [[B:%.*]]) { |
| 211 | +; CHECK-NEXT: entry: |
| 212 | +; CHECK-NEXT: [[OR1:%.*]] = or i64 [[A]], 3 |
| 213 | +; CHECK-NEXT: [[OR2:%.*]] = or i64 [[B]], 192 |
| 214 | +; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i64 [[OR1]], i64 [[OR2]] |
| 215 | +; CHECK-NEXT: [[RET1:%.*]] = and i64 [[S]], 8 |
| 216 | +; CHECK-NEXT: [[RET2:%.*]] = and i64 [[S]], 16 |
| 217 | +; CHECK-NEXT: call void @use(i64 [[RET1]]) |
| 218 | +; CHECK-NEXT: call void @use(i64 [[RET2]]) |
| 219 | +; CHECK-NEXT: ret void |
| 220 | +; |
| 221 | +entry: |
| 222 | + %or1 = or i64 %a, 3 ; Mask: 0000 0011 |
| 223 | + %or2 = or i64 %b, 192 ; Mask: 1100 0000 |
| 224 | + %s = select i1 %c, i64 %or1, i64 %or2 |
| 225 | + %ret1 = and i64 %s, 8 ; Demanded bits: 0000 1000 |
| 226 | + %ret2 = and i64 %s, 16 ; Demanded bits: 0001 0000 |
| 227 | + call void @use(i64 %ret1) |
| 228 | + call void @use(i64 %ret2) |
| 229 | + ret void |
| 230 | +} |
| 231 | + |
| 232 | +define void @select_of_xor(i1 %c, i64 %a, i64 %b) { |
| 233 | +; CHECK-LABEL: define void @select_of_xor( |
| 234 | +; CHECK-SAME: i1 [[C:%.*]], i64 [[A:%.*]], i64 [[B:%.*]]) { |
| 235 | +; CHECK-NEXT: entry: |
| 236 | +; CHECK-NEXT: [[XOR1:%.*]] = xor i64 [[A]], 128 |
| 237 | +; CHECK-NEXT: [[XOR2:%.*]] = xor i64 [[B]], 36 |
| 238 | +; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], i64 [[XOR1]], i64 [[XOR2]] |
| 239 | +; CHECK-NEXT: [[RET1:%.*]] = and i64 [[S]], 8 |
| 240 | +; CHECK-NEXT: [[RET2:%.*]] = and i64 [[S]], 16 |
| 241 | +; CHECK-NEXT: call void @use(i64 [[RET1]]) |
| 242 | +; CHECK-NEXT: call void @use(i64 [[RET2]]) |
| 243 | +; CHECK-NEXT: ret void |
| 244 | +; |
| 245 | +entry: |
| 246 | + %xor1 = xor i64 %a, 128 ; Mask: 1000 0000 |
| 247 | + %xor2 = xor i64 %b, 36 ; Mask: 0010 0100 |
| 248 | + %s = select i1 %c, i64 %xor1, i64 %xor2 |
| 249 | + %ret1 = and i64 %s, 8 ; Demanded bits: 0000 1000 |
| 250 | + %ret2 = and i64 %s, 16 ; Demanded bits: 0001 0000 |
| 251 | + call void @use(i64 %ret1) |
| 252 | + call void @use(i64 %ret2) |
| 253 | + ret void |
| 254 | +} |
| 255 | + |
| 256 | +define void @select_vectorized(i1 %c, <2 x i8> %a, <2 x i8> %b) { |
| 257 | +; CHECK-LABEL: define void @select_vectorized( |
| 258 | +; CHECK-SAME: i1 [[C:%.*]], <2 x i8> [[A:%.*]], <2 x i8> [[B:%.*]]) { |
| 259 | +; CHECK-NEXT: entry: |
| 260 | +; CHECK-NEXT: [[AND1:%.*]] = and <2 x i8> [[A]], <i8 28, i8 28> |
| 261 | +; CHECK-NEXT: [[AND2:%.*]] = and <2 x i8> [[B]], <i8 29, i8 29> |
| 262 | +; CHECK-NEXT: [[S:%.*]] = select i1 [[C]], <2 x i8> [[AND1]], <2 x i8> [[AND2]] |
| 263 | +; CHECK-NEXT: [[RET1:%.*]] = and <2 x i8> [[S]], <i8 4, i8 4> |
| 264 | +; CHECK-NEXT: [[RET2:%.*]] = and <2 x i8> [[S]], <i8 12, i8 12> |
| 265 | +; CHECK-NEXT: call void @use3(<2 x i8> [[RET1]]) |
| 266 | +; CHECK-NEXT: call void @use3(<2 x i8> [[RET2]]) |
| 267 | +; CHECK-NEXT: ret void |
| 268 | +; |
| 269 | +entry: |
| 270 | + %and1 = and <2 x i8> %a, <i8 28, i8 28> |
| 271 | + %and2 = and <2 x i8> %b, <i8 29, i8 29> |
| 272 | + %s = select i1 %c, <2 x i8> %and1, <2 x i8> %and2 |
| 273 | + %ret1 = and <2 x i8> %s, <i8 4, i8 4> |
| 274 | + %ret2 = and <2 x i8> %s, <i8 12, i8 12> |
| 275 | + call void @use3(<2 x i8> %ret1) |
| 276 | + call void @use3(<2 x i8> %ret2) |
| 277 | + ret void |
| 278 | +} |
| 279 | + |
| 280 | +declare void @use(i64) |
| 281 | +declare void @use2(i64, i64) |
| 282 | +declare void @use3(<2 x i8>) |
0 commit comments