1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -passes=instsimplify -S | FileCheck %s 3 4define i32 @poison(i32 %x) { 5; CHECK-LABEL: @poison( 6; CHECK-NEXT: ret i32 poison 7; 8 %v = xor i32 %x, poison 9 ret i32 %v 10} 11 12define i4 @xor_and_or_not_commute0(i4 %a, i4 %b) { 13; CHECK-LABEL: @xor_and_or_not_commute0( 14; CHECK-NEXT: [[NOT:%.*]] = xor i4 [[A:%.*]], -1 15; CHECK-NEXT: ret i4 [[NOT]] 16; 17 %and = and i4 %a, %b 18 %not = xor i4 %a, -1 19 %or = or i4 %not, %b 20 %r = xor i4 %and, %or 21 ret i4 %r 22} 23 24define <2 x i4> @xor_and_or_not_commute1(<2 x i4> %a, <2 x i4> %b) { 25; CHECK-LABEL: @xor_and_or_not_commute1( 26; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i4> [[A:%.*]], splat (i4 -1) 27; CHECK-NEXT: ret <2 x i4> [[NOT]] 28; 29 %and = and <2 x i4> %a, %b 30 %not = xor <2 x i4> %a, <i4 -1, i4 -1> 31 %or = or <2 x i4> %not, %b 32 %r = xor <2 x i4> %or, %and 33 ret <2 x i4> %r 34} 35 36define i74 @xor_and_or_not_commute2(i74 %a, i74 %b) { 37; CHECK-LABEL: @xor_and_or_not_commute2( 38; CHECK-NEXT: [[NOT:%.*]] = xor i74 [[A:%.*]], -1 39; CHECK-NEXT: ret i74 [[NOT]] 40; 41 %and = and i74 %b, %a 42 %not = xor i74 %a, -1 43 %or = or i74 %not, %b 44 %r = xor i74 %and, %or 45 ret i74 %r 46} 47 48define <2 x i4> @xor_and_or_not_commute3(<2 x i4> %a, <2 x i4> %b) { 49; CHECK-LABEL: @xor_and_or_not_commute3( 50; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i4> [[A:%.*]], splat (i4 -1) 51; CHECK-NEXT: ret <2 x i4> [[NOT]] 52; 53 %and = and <2 x i4> %b, %a 54 %not = xor <2 x i4> %a, <i4 -1, i4 -1> 55 %or = or <2 x i4> %not, %b 56 %r = xor <2 x i4> %or, %and 57 ret <2 x i4> %r 58} 59 60define i8 @xor_and_or_not_commute4(i8 %a, i8 %b) { 61; CHECK-LABEL: @xor_and_or_not_commute4( 62; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[A:%.*]], -1 63; CHECK-NEXT: ret i8 [[NOT]] 64; 65 %and = and i8 %a, %b 66 %not = xor i8 %a, -1 67 %or = or i8 %b, %not 68 %r = xor i8 %and, %or 69 ret i8 %r 70} 71 72define i8 @xor_and_or_not_commute5(i8 %a, i8 %b) { 73; CHECK-LABEL: @xor_and_or_not_commute5( 74; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[A:%.*]], -1 75; CHECK-NEXT: ret i8 [[NOT]] 76; 77 %and = and i8 %a, %b 78 %not = xor i8 %a, -1 79 %or = or i8 %b, %not 80 %r = xor i8 %or, %and 81 ret i8 %r 82} 83 84define i8 @xor_and_or_not_commute6(i8 %a, i8 %b) { 85; CHECK-LABEL: @xor_and_or_not_commute6( 86; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[A:%.*]], -1 87; CHECK-NEXT: ret i8 [[NOT]] 88; 89 %and = and i8 %b, %a 90 %not = xor i8 %a, -1 91 %or = or i8 %b, %not 92 %r = xor i8 %and, %or 93 ret i8 %r 94} 95 96define i8 @xor_and_or_not_commute7(i8 %a, i8 %b) { 97; CHECK-LABEL: @xor_and_or_not_commute7( 98; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[A:%.*]], -1 99; CHECK-NEXT: ret i8 [[NOT]] 100; 101 %and = and i8 %b, %a 102 %not = xor i8 %a, -1 103 %or = or i8 %b, %not 104 %r = xor i8 %or, %and 105 ret i8 %r 106} 107 108; negative test - must match specific values 109 110define i4 @xor_and_or_not_wrong_val1(i4 %a, i4 %b, i4 %c) { 111; CHECK-LABEL: @xor_and_or_not_wrong_val1( 112; CHECK-NEXT: [[AND:%.*]] = and i4 [[A:%.*]], [[C:%.*]] 113; CHECK-NEXT: [[NOT:%.*]] = xor i4 [[A]], -1 114; CHECK-NEXT: [[OR:%.*]] = or i4 [[NOT]], [[B:%.*]] 115; CHECK-NEXT: [[R:%.*]] = xor i4 [[AND]], [[OR]] 116; CHECK-NEXT: ret i4 [[R]] 117; 118 %and = and i4 %a, %c 119 %not = xor i4 %a, -1 120 %or = or i4 %not, %b 121 %r = xor i4 %and, %or 122 ret i4 %r 123} 124 125; negative test - must match specific values 126 127define i4 @xor_and_or_not_wrong_val2(i4 %a, i4 %b, i4 %c) { 128; CHECK-LABEL: @xor_and_or_not_wrong_val2( 129; CHECK-NEXT: [[AND:%.*]] = and i4 [[C:%.*]], [[B:%.*]] 130; CHECK-NEXT: [[NOT:%.*]] = xor i4 [[A:%.*]], -1 131; CHECK-NEXT: [[OR:%.*]] = or i4 [[NOT]], [[B]] 132; CHECK-NEXT: [[R:%.*]] = xor i4 [[AND]], [[OR]] 133; CHECK-NEXT: ret i4 [[R]] 134; 135 %and = and i4 %c, %b 136 %not = xor i4 %a, -1 137 %or = or i4 %not, %b 138 %r = xor i4 %and, %or 139 ret i4 %r 140} 141 142; negative test - incorrect to propagate undef element 143 144define <2 x i4> @xor_and_or_not_undef_elt(<2 x i4> %a, <2 x i4> %b) { 145; CHECK-LABEL: @xor_and_or_not_undef_elt( 146; CHECK-NEXT: [[AND:%.*]] = and <2 x i4> [[B:%.*]], [[A:%.*]] 147; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i4> [[A]], <i4 -1, i4 undef> 148; CHECK-NEXT: [[OR:%.*]] = or <2 x i4> [[NOT]], [[B]] 149; CHECK-NEXT: [[R:%.*]] = xor <2 x i4> [[OR]], [[AND]] 150; CHECK-NEXT: ret <2 x i4> [[R]] 151; 152 %and = and <2 x i4> %b, %a 153 %not = xor <2 x i4> %a, <i4 -1, i4 undef> 154 %or = or <2 x i4> %not, %b 155 %r = xor <2 x i4> %or, %and 156 ret <2 x i4> %r 157} 158 159; but correct to propagate poison element 160 161define <2 x i4> @xor_and_or_not_poison_elt(<2 x i4> %a, <2 x i4> %b) { 162; CHECK-LABEL: @xor_and_or_not_poison_elt( 163; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i4> [[A:%.*]], <i4 -1, i4 poison> 164; CHECK-NEXT: ret <2 x i4> [[NOT]] 165; 166 %and = and <2 x i4> %b, %a 167 %not = xor <2 x i4> %a, <i4 -1, i4 poison> 168 %or = or <2 x i4> %not, %b 169 %r = xor <2 x i4> %or, %and 170 ret <2 x i4> %r 171} 172 173define i4 @xor_or_and_not_commute0(i4 %a, i4 %b) { 174; CHECK-LABEL: @xor_or_and_not_commute0( 175; CHECK-NEXT: ret i4 [[A:%.*]] 176; 177 %not = xor i4 %a, -1 178 %and = and i4 %not, %b 179 %or = or i4 %a, %b 180 %r = xor i4 %and, %or 181 ret i4 %r 182} 183 184define <2 x i4> @xor_or_and_not_commute1(<2 x i4> %a, <2 x i4> %b) { 185; CHECK-LABEL: @xor_or_and_not_commute1( 186; CHECK-NEXT: ret <2 x i4> [[A:%.*]] 187; 188 %not = xor <2 x i4> %a, <i4 -1, i4 -1> 189 %and = and <2 x i4> %not, %b 190 %or = or <2 x i4> %a, %b 191 %r = xor <2 x i4> %or, %and 192 ret <2 x i4> %r 193} 194 195define i74 @xor_or_and_not_commute2(i74 %a, i74 %b) { 196; CHECK-LABEL: @xor_or_and_not_commute2( 197; CHECK-NEXT: ret i74 [[A:%.*]] 198; 199 %not = xor i74 %a, -1 200 %and = and i74 %b, %not 201 %or = or i74 %a, %b 202 %r = xor i74 %and, %or 203 ret i74 %r 204} 205 206define <2 x i4> @xor_or_and_not_commute3(<2 x i4> %a, <2 x i4> %b) { 207; CHECK-LABEL: @xor_or_and_not_commute3( 208; CHECK-NEXT: ret <2 x i4> [[A:%.*]] 209; 210 %not = xor <2 x i4> %a, <i4 -1, i4 -1> 211 %and = and <2 x i4> %b, %not 212 %or = or <2 x i4> %a, %b 213 %r = xor <2 x i4> %or, %and 214 ret <2 x i4> %r 215} 216 217define i8 @xor_or_and_not_commute4(i8 %a, i8 %b) { 218; CHECK-LABEL: @xor_or_and_not_commute4( 219; CHECK-NEXT: ret i8 [[A:%.*]] 220; 221 %not = xor i8 %a, -1 222 %and = and i8 %not, %b 223 %or = or i8 %b, %a 224 %r = xor i8 %and, %or 225 ret i8 %r 226} 227 228define i8 @xor_or_and_not_commute5(i8 %a, i8 %b) { 229; CHECK-LABEL: @xor_or_and_not_commute5( 230; CHECK-NEXT: ret i8 [[A:%.*]] 231; 232 %not = xor i8 %a, -1 233 %and = and i8 %not, %b 234 %or = or i8 %b, %a 235 %r = xor i8 %or, %and 236 ret i8 %r 237} 238 239define i8 @xor_or_and_not_commute6(i8 %a, i8 %b) { 240; CHECK-LABEL: @xor_or_and_not_commute6( 241; CHECK-NEXT: ret i8 [[A:%.*]] 242; 243 %not = xor i8 %a, -1 244 %and = and i8 %b, %not 245 %or = or i8 %b, %a 246 %r = xor i8 %and, %or 247 ret i8 %r 248} 249 250define i8 @xor_or_and_not_commute7(i8 %a, i8 %b) { 251; CHECK-LABEL: @xor_or_and_not_commute7( 252; CHECK-NEXT: ret i8 [[A:%.*]] 253; 254 %not = xor i8 %a, -1 255 %and = and i8 %b, %not 256 %or = or i8 %b, %a 257 %r = xor i8 %or, %and 258 ret i8 %r 259} 260 261; negative test - must match specific values 262 263define i4 @xor_or_and_not_wrong_val1(i4 %a, i4 %b, i4 %c) { 264; CHECK-LABEL: @xor_or_and_not_wrong_val1( 265; CHECK-NEXT: [[NOT:%.*]] = xor i4 [[A:%.*]], -1 266; CHECK-NEXT: [[AND:%.*]] = and i4 [[NOT]], [[C:%.*]] 267; CHECK-NEXT: [[OR:%.*]] = or i4 [[A]], [[B:%.*]] 268; CHECK-NEXT: [[R:%.*]] = xor i4 [[AND]], [[OR]] 269; CHECK-NEXT: ret i4 [[R]] 270; 271 %not = xor i4 %a, -1 272 %and = and i4 %not, %c 273 %or = or i4 %a, %b 274 %r = xor i4 %and, %or 275 ret i4 %r 276} 277 278; negative test - must match specific values 279 280define i4 @xor_or_and_not_wrong_val2(i4 %a, i4 %b, i4 %c) { 281; CHECK-LABEL: @xor_or_and_not_wrong_val2( 282; CHECK-NEXT: [[AND:%.*]] = and i4 [[C:%.*]], [[B:%.*]] 283; CHECK-NEXT: [[OR:%.*]] = or i4 [[A:%.*]], [[B]] 284; CHECK-NEXT: [[R:%.*]] = xor i4 [[AND]], [[OR]] 285; CHECK-NEXT: ret i4 [[R]] 286; 287 %not = xor i4 %a, -1 288 %and = and i4 %c, %b 289 %or = or i4 %a, %b 290 %r = xor i4 %and, %or 291 ret i4 %r 292} 293 294define <2 x i4> @xor_or_and_not_poison_elt(<2 x i4> %a, <2 x i4> %b) { 295; CHECK-LABEL: @xor_or_and_not_poison_elt( 296; CHECK-NEXT: ret <2 x i4> [[A:%.*]] 297; 298 %not = xor <2 x i4> %a, <i4 -1, i4 poison> 299 %and = and <2 x i4> %b, %not 300 %or = or <2 x i4> %a, %b 301 %r = xor <2 x i4> %or, %and 302 ret <2 x i4> %r 303} 304