1142 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=instcombine -S | FileCheck %s3 4declare void @use1(i1)5declare void @use8(i8)6declare void @f1()7declare void @f2()8 9define i32 @test1(i32 %A) {10; CHECK-LABEL: @test1(11; CHECK-NEXT: ret i32 [[A:%.*]]12;13 %B = xor i32 %A, -114 %C = xor i32 %B, -115 ret i32 %C16}17 18define i1 @invert_icmp(i32 %A, i32 %B) {19; CHECK-LABEL: @invert_icmp(20; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp sgt i32 [[A:%.*]], [[B:%.*]]21; CHECK-NEXT: ret i1 [[CMP_NOT]]22;23 %cmp = icmp sle i32 %A, %B24 %not = xor i1 %cmp, true25 ret i1 %not26}27 28; PR157029 30define i1 @invert_fcmp(float %X, float %Y) {31; CHECK-LABEL: @invert_fcmp(32; CHECK-NEXT: [[CMP:%.*]] = fcmp uge float [[X:%.*]], [[Y:%.*]]33; CHECK-NEXT: ret i1 [[CMP]]34;35 %cmp = fcmp olt float %X, %Y36 %not = xor i1 %cmp, true37 ret i1 %not38}39 40; PR229841 42define i1 @not_not_cmp(i32 %a, i32 %b) {43; CHECK-LABEL: @not_not_cmp(44; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[A:%.*]], [[B:%.*]]45; CHECK-NEXT: ret i1 [[CMP]]46;47 %nota = xor i32 %a, -148 %notb = xor i32 %b, -149 %cmp = icmp slt i32 %nota, %notb50 ret i1 %cmp51}52 53define <2 x i1> @not_not_cmp_vector(<2 x i32> %a, <2 x i32> %b) {54; CHECK-LABEL: @not_not_cmp_vector(55; CHECK-NEXT: [[CMP:%.*]] = icmp ult <2 x i32> [[A:%.*]], [[B:%.*]]56; CHECK-NEXT: ret <2 x i1> [[CMP]]57;58 %nota = xor <2 x i32> %a, <i32 -1, i32 -1>59 %notb = xor <2 x i32> %b, <i32 -1, i32 -1>60 %cmp = icmp ugt <2 x i32> %nota, %notb61 ret <2 x i1> %cmp62}63 64define i1 @not_cmp_constant(i32 %a) {65; CHECK-LABEL: @not_cmp_constant(66; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[A:%.*]], -4367; CHECK-NEXT: ret i1 [[CMP]]68;69 %nota = xor i32 %a, -170 %cmp = icmp ugt i32 %nota, 4271 ret i1 %cmp72}73 74define <2 x i1> @not_cmp_constant_vector(<2 x i32> %a) {75; CHECK-LABEL: @not_cmp_constant_vector(76; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[A:%.*]], splat (i32 -43)77; CHECK-NEXT: ret <2 x i1> [[CMP]]78;79 %nota = xor <2 x i32> %a, <i32 -1, i32 -1>80 %cmp = icmp slt <2 x i32> %nota, <i32 42, i32 42>81 ret <2 x i1> %cmp82}83 84define <2 x i1> @test7(<2 x i32> %A, <2 x i32> %B) {85; CHECK-LABEL: @test7(86; CHECK-NEXT: [[COND_NOT:%.*]] = icmp sgt <2 x i32> [[A:%.*]], [[B:%.*]]87; CHECK-NEXT: ret <2 x i1> [[COND_NOT]]88;89 %cond = icmp sle <2 x i32> %A, %B90 %Ret = xor <2 x i1> %cond, <i1 true, i1 true>91 ret <2 x i1> %Ret92}93 94define i32 @not_ashr_not(i32 %A, i32 %B) {95; CHECK-LABEL: @not_ashr_not(96; CHECK-NEXT: [[NOT1_NOT:%.*]] = ashr i32 [[A:%.*]], [[B:%.*]]97; CHECK-NEXT: ret i32 [[NOT1_NOT]]98;99 %not1 = xor i32 %A, -1100 %ashr = ashr i32 %not1, %B101 %not2 = xor i32 %ashr, -1102 ret i32 %not2103}104 105define i8 @not_ashr_const(i8 %x) {106; CHECK-LABEL: @not_ashr_const(107; CHECK-NEXT: [[NOT:%.*]] = lshr i8 41, [[X:%.*]]108; CHECK-NEXT: ret i8 [[NOT]]109;110 %shr = ashr i8 -42, %x111 %not = xor i8 %shr, -1112 ret i8 %not113}114 115define <2 x i8> @not_ashr_const_splat(<2 x i8> %x) {116; CHECK-LABEL: @not_ashr_const_splat(117; CHECK-NEXT: [[NOT:%.*]] = lshr <2 x i8> splat (i8 41), [[X:%.*]]118; CHECK-NEXT: ret <2 x i8> [[NOT]]119;120 %shr = ashr <2 x i8> <i8 -42, i8 -42>, %x121 %not = xor <2 x i8> %shr, <i8 -1, i8 -1>122 ret <2 x i8> %not123}124 125; We can't get rid of the 'not' on a logical shift of a negative constant.126 127define i8 @not_lshr_const_negative(i8 %x) {128; CHECK-LABEL: @not_lshr_const_negative(129; CHECK-NEXT: [[SHR:%.*]] = lshr i8 -42, [[X:%.*]]130; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[SHR]], -1131; CHECK-NEXT: ret i8 [[NOT]]132;133 %shr = lshr i8 -42, %x134 %not = xor i8 %shr, -1135 ret i8 %not136}137 138define i8 @not_lshr_const(i8 %x) {139; CHECK-LABEL: @not_lshr_const(140; CHECK-NEXT: [[NOT:%.*]] = ashr i8 -43, [[X:%.*]]141; CHECK-NEXT: ret i8 [[NOT]]142;143 %shr = lshr i8 42, %x144 %not = xor i8 %shr, -1145 ret i8 %not146}147 148define <2 x i8> @not_lshr_const_splat(<2 x i8> %x) {149; CHECK-LABEL: @not_lshr_const_splat(150; CHECK-NEXT: [[NOT:%.*]] = ashr <2 x i8> splat (i8 -43), [[X:%.*]]151; CHECK-NEXT: ret <2 x i8> [[NOT]]152;153 %shr = lshr <2 x i8> <i8 42, i8 42>, %x154 %not = xor <2 x i8> %shr, <i8 -1, i8 -1>155 ret <2 x i8> %not156}157 158define i32 @not_sub(i32 %y) {159; CHECK-LABEL: @not_sub(160; CHECK-NEXT: [[R:%.*]] = add i32 [[Y:%.*]], -124161; CHECK-NEXT: ret i32 [[R]]162;163 %s = sub i32 123, %y164 %r = xor i32 %s, -1165 ret i32 %r166}167 168define i32 @not_sub_extra_use(i32 %y, ptr %p) {169; CHECK-LABEL: @not_sub_extra_use(170; CHECK-NEXT: [[S:%.*]] = sub i32 123, [[Y:%.*]]171; CHECK-NEXT: store i32 [[S]], ptr [[P:%.*]], align 4172; CHECK-NEXT: [[R:%.*]] = add i32 [[Y]], -124173; CHECK-NEXT: ret i32 [[R]]174;175 %s = sub i32 123, %y176 store i32 %s, ptr %p177 %r = xor i32 %s, -1178 ret i32 %r179}180 181define <2 x i32> @not_sub_splat(<2 x i32> %y) {182; CHECK-LABEL: @not_sub_splat(183; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y:%.*]], splat (i32 -124)184; CHECK-NEXT: ret <2 x i32> [[R]]185;186 %s = sub <2 x i32> <i32 123, i32 123>, %y187 %r = xor <2 x i32> %s, <i32 -1, i32 -1>188 ret <2 x i32> %r189}190 191define <2 x i32> @not_sub_extra_use_splat(<2 x i32> %y, ptr %p) {192; CHECK-LABEL: @not_sub_extra_use_splat(193; CHECK-NEXT: [[S:%.*]] = sub <2 x i32> splat (i32 123), [[Y:%.*]]194; CHECK-NEXT: store <2 x i32> [[S]], ptr [[P:%.*]], align 8195; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y]], splat (i32 -124)196; CHECK-NEXT: ret <2 x i32> [[R]]197;198 %s = sub <2 x i32> <i32 123, i32 123>, %y199 store <2 x i32> %s, ptr %p200 %r = xor <2 x i32> %s, <i32 -1, i32 -1>201 ret <2 x i32> %r202}203 204define <2 x i32> @not_sub_vec(<2 x i32> %y) {205; CHECK-LABEL: @not_sub_vec(206; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y:%.*]], <i32 -43, i32 -124>207; CHECK-NEXT: ret <2 x i32> [[R]]208;209 %s = sub <2 x i32> <i32 42, i32 123>, %y210 %r = xor <2 x i32> %s, <i32 -1, i32 -1>211 ret <2 x i32> %r212}213 214define <2 x i32> @not_sub_extra_use_vec(<2 x i32> %y, ptr %p) {215; CHECK-LABEL: @not_sub_extra_use_vec(216; CHECK-NEXT: [[S:%.*]] = sub <2 x i32> <i32 123, i32 42>, [[Y:%.*]]217; CHECK-NEXT: store <2 x i32> [[S]], ptr [[P:%.*]], align 8218; CHECK-NEXT: [[R:%.*]] = add <2 x i32> [[Y]], <i32 -124, i32 -43>219; CHECK-NEXT: ret <2 x i32> [[R]]220;221 %s = sub <2 x i32> <i32 123, i32 42>, %y222 store <2 x i32> %s, ptr %p223 %r = xor <2 x i32> %s, <i32 -1, i32 -1>224 ret <2 x i32> %r225}226 227; ~(X + C) --> -X - C - 1 --> -(C + 1) - X228 229define i32 @not_add(i32 %x) {230; CHECK-LABEL: @not_add(231; CHECK-NEXT: [[R:%.*]] = sub i32 -124, [[X:%.*]]232; CHECK-NEXT: ret i32 [[R]]233;234 %a = add i32 %x, 123235 %r = xor i32 %a, -1236 ret i32 %r237}238 239define <2 x i32> @not_add_splat(<2 x i32> %x) {240; CHECK-LABEL: @not_add_splat(241; CHECK-NEXT: [[R:%.*]] = sub <2 x i32> splat (i32 -124), [[X:%.*]]242; CHECK-NEXT: ret <2 x i32> [[R]]243;244 %a = add <2 x i32> %x, <i32 123, i32 123>245 %r = xor <2 x i32> %a, <i32 -1, i32 -1>246 ret <2 x i32> %r247}248 249define <2 x i32> @not_add_vec(<2 x i32> %x) {250; CHECK-LABEL: @not_add_vec(251; CHECK-NEXT: [[R:%.*]] = sub <2 x i32> <i32 -43, i32 -124>, [[X:%.*]]252; CHECK-NEXT: ret <2 x i32> [[R]]253;254 %a = add <2 x i32> %x, <i32 42, i32 123>255 %r = xor <2 x i32> %a, <i32 -1, i32 -1>256 ret <2 x i32> %r257}258 259define i1 @not_select_cmp_cmp(i32 %x, i32 %y, float %z, float %w, i1 %cond) {260; CHECK-LABEL: @not_select_cmp_cmp(261; CHECK-NEXT: [[CMPT:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]262; CHECK-NEXT: [[CMPF:%.*]] = fcmp ole float [[Z:%.*]], [[W:%.*]]263; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i1 [[CMPT]], i1 [[CMPF]]264; CHECK-NEXT: ret i1 [[SEL]]265;266 %cmpt = icmp sle i32 %x, %y267 %cmpf = fcmp ugt float %z, %w268 %sel = select i1 %cond, i1 %cmpt, i1 %cmpf269 %not = xor i1 %sel, true270 ret i1 %not271}272 273; TODO: Missed canonicalization - hoist 'not'?274 275define i1 @not_select_cmp_cmp_extra_use1(i32 %x, i32 %y, float %z, float %w, i1 %cond) {276; CHECK-LABEL: @not_select_cmp_cmp_extra_use1(277; CHECK-NEXT: [[CMPT:%.*]] = icmp sle i32 [[X:%.*]], [[Y:%.*]]278; CHECK-NEXT: call void @use1(i1 [[CMPT]])279; CHECK-NEXT: [[CMPF:%.*]] = fcmp ugt float [[Z:%.*]], [[W:%.*]]280; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i1 [[CMPT]], i1 [[CMPF]]281; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[SEL]], true282; CHECK-NEXT: ret i1 [[NOT]]283;284 %cmpt = icmp sle i32 %x, %y285 call void @use1(i1 %cmpt)286 %cmpf = fcmp ugt float %z, %w287 %sel = select i1 %cond, i1 %cmpt, i1 %cmpf288 %not = xor i1 %sel, true289 ret i1 %not290}291 292; TODO: Missed canonicalization - hoist 'not'?293 294define i1 @not_select_cmp_cmp_extra_use2(i32 %x, i32 %y, float %z, float %w, i1 %cond) {295; CHECK-LABEL: @not_select_cmp_cmp_extra_use2(296; CHECK-NEXT: [[CMPT:%.*]] = icmp sle i32 [[X:%.*]], [[Y:%.*]]297; CHECK-NEXT: [[CMPF:%.*]] = fcmp ugt float [[Z:%.*]], [[W:%.*]]298; CHECK-NEXT: call void @use1(i1 [[CMPF]])299; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i1 [[CMPT]], i1 [[CMPF]]300; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[SEL]], true301; CHECK-NEXT: ret i1 [[NOT]]302;303 %cmpt = icmp sle i32 %x, %y304 %cmpf = fcmp ugt float %z, %w305 call void @use1(i1 %cmpf)306 %sel = select i1 %cond, i1 %cmpt, i1 %cmpf307 %not = xor i1 %sel, true308 ret i1 %not309}310 311; Negative test - extra uses would require more instructions.312 313define i1 @not_select_cmp_cmp_extra_use3(i32 %x, i32 %y, float %z, float %w, i1 %cond) {314; CHECK-LABEL: @not_select_cmp_cmp_extra_use3(315; CHECK-NEXT: [[CMPT:%.*]] = icmp sle i32 [[X:%.*]], [[Y:%.*]]316; CHECK-NEXT: call void @use1(i1 [[CMPT]])317; CHECK-NEXT: [[CMPF:%.*]] = fcmp ugt float [[Z:%.*]], [[W:%.*]]318; CHECK-NEXT: call void @use1(i1 [[CMPF]])319; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i1 [[CMPT]], i1 [[CMPF]]320; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[SEL]], true321; CHECK-NEXT: ret i1 [[NOT]]322;323 %cmpt = icmp sle i32 %x, %y324 call void @use1(i1 %cmpt)325 %cmpf = fcmp ugt float %z, %w326 call void @use1(i1 %cmpf)327 %sel = select i1 %cond, i1 %cmpt, i1 %cmpf328 %not = xor i1 %sel, true329 ret i1 %not330}331 332; Negative test - extra uses would require more instructions.333 334define i1 @not_select_cmp_cmp_extra_use4(i32 %x, i32 %y, float %z, float %w, i1 %cond) {335; CHECK-LABEL: @not_select_cmp_cmp_extra_use4(336; CHECK-NEXT: [[CMPT:%.*]] = icmp sle i32 [[X:%.*]], [[Y:%.*]]337; CHECK-NEXT: [[CMPF:%.*]] = fcmp ugt float [[Z:%.*]], [[W:%.*]]338; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i1 [[CMPT]], i1 [[CMPF]]339; CHECK-NEXT: call void @use1(i1 [[SEL]])340; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[SEL]], true341; CHECK-NEXT: ret i1 [[NOT]]342;343 %cmpt = icmp sle i32 %x, %y344 %cmpf = fcmp ugt float %z, %w345 %sel = select i1 %cond, i1 %cmpt, i1 %cmpf346 call void @use1(i1 %sel)347 %not = xor i1 %sel, true348 ret i1 %not349}350 351; TODO: Missed canonicalization - hoist 'not'?352 353define i1 @not_select_cmpt(double %x, double %y, i1 %z, i1 %cond) {354; CHECK-LABEL: @not_select_cmpt(355; CHECK-NEXT: [[CMPT:%.*]] = fcmp oeq double [[X:%.*]], [[Y:%.*]]356; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i1 [[CMPT]], i1 [[Z:%.*]]357; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[SEL]], true358; CHECK-NEXT: ret i1 [[NOT]]359;360 %cmpt = fcmp oeq double %x, %y361 %sel = select i1 %cond, i1 %cmpt, i1 %z362 %not = xor i1 %sel, true363 ret i1 %not364}365 366; TODO: Missed canonicalization - hoist 'not'?367 368define i1 @not_select_cmpf(i1 %x, i32 %z, i32 %w, i1 %cond) {369; CHECK-LABEL: @not_select_cmpf(370; CHECK-NEXT: [[CMPF:%.*]] = icmp ugt i32 [[Z:%.*]], [[W:%.*]]371; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i1 [[X:%.*]], i1 [[CMPF]]372; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[SEL]], true373; CHECK-NEXT: ret i1 [[NOT]]374;375 %cmpf = icmp ugt i32 %z, %w376 %sel = select i1 %cond, i1 %x, i1 %cmpf377 %not = xor i1 %sel, true378 ret i1 %not379}380 381define i1 @not_select_cmpt_extra_use(double %x, double %y, i1 %z, i1 %cond) {382; CHECK-LABEL: @not_select_cmpt_extra_use(383; CHECK-NEXT: [[CMPT:%.*]] = fcmp oeq double [[X:%.*]], [[Y:%.*]]384; CHECK-NEXT: call void @use1(i1 [[CMPT]])385; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i1 [[CMPT]], i1 [[Z:%.*]]386; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[SEL]], true387; CHECK-NEXT: ret i1 [[NOT]]388;389 %cmpt = fcmp oeq double %x, %y390 call void @use1(i1 %cmpt)391 %sel = select i1 %cond, i1 %cmpt, i1 %z392 %not = xor i1 %sel, true393 ret i1 %not394}395 396define i1 @not_select_cmpf_extra_use(i1 %x, i32 %z, i32 %w, i1 %cond) {397; CHECK-LABEL: @not_select_cmpf_extra_use(398; CHECK-NEXT: [[CMPF:%.*]] = icmp ugt i32 [[Z:%.*]], [[W:%.*]]399; CHECK-NEXT: call void @use1(i1 [[CMPF]])400; CHECK-NEXT: [[SEL:%.*]] = select i1 [[COND:%.*]], i1 [[X:%.*]], i1 [[CMPF]]401; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[SEL]], true402; CHECK-NEXT: ret i1 [[NOT]]403;404 %cmpf = icmp ugt i32 %z, %w405 call void @use1(i1 %cmpf)406 %sel = select i1 %cond, i1 %x, i1 %cmpf407 %not = xor i1 %sel, true408 ret i1 %not409}410 411define i8 @not_or_neg(i8 %x, i8 %y) {412; CHECK-LABEL: @not_or_neg(413; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[Y:%.*]], -1414; CHECK-NEXT: [[TMP2:%.*]] = xor i8 [[X:%.*]], -1415; CHECK-NEXT: [[NOT:%.*]] = and i8 [[TMP1]], [[TMP2]]416; CHECK-NEXT: ret i8 [[NOT]]417;418 %s = sub i8 0, %y419 %o = or i8 %s, %x420 %not = xor i8 %o, -1421 ret i8 %not422}423 424define <3 x i5> @not_or_neg_commute_vec(<3 x i5> %x, <3 x i5> %p) {425; CHECK-LABEL: @not_or_neg_commute_vec(426; CHECK-NEXT: [[Y:%.*]] = mul <3 x i5> [[P:%.*]], <i5 1, i5 2, i5 3>427; CHECK-NEXT: [[TMP1:%.*]] = add <3 x i5> [[X:%.*]], splat (i5 -1)428; CHECK-NEXT: [[TMP2:%.*]] = xor <3 x i5> [[Y]], splat (i5 -1)429; CHECK-NEXT: [[NOT:%.*]] = and <3 x i5> [[TMP1]], [[TMP2]]430; CHECK-NEXT: ret <3 x i5> [[NOT]]431;432 %y = mul <3 x i5> %p, <i5 1, i5 2, i5 3> ; thwart complexity-based-canonicalization433 %s = sub <3 x i5> <i5 0, i5 0, i5 poison>, %x434 %o = or <3 x i5> %y, %s435 %not = xor <3 x i5> %o, <i5 -1, i5 poison, i5 -1>436 ret <3 x i5> %not437}438 439; negative test440 441define i8 @not_or_neg_use1(i8 %x, i8 %y) {442; CHECK-LABEL: @not_or_neg_use1(443; CHECK-NEXT: [[S:%.*]] = sub i8 0, [[Y:%.*]]444; CHECK-NEXT: call void @use8(i8 [[S]])445; CHECK-NEXT: [[O:%.*]] = or i8 [[X:%.*]], [[S]]446; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[O]], -1447; CHECK-NEXT: ret i8 [[NOT]]448;449 %s = sub i8 0, %y450 call void @use8(i8 %s)451 %o = or i8 %s, %x452 %not = xor i8 %o, -1453 ret i8 %not454}455 456; negative test457 458define i8 @not_or_neg_use2(i8 %x, i8 %y) {459; CHECK-LABEL: @not_or_neg_use2(460; CHECK-NEXT: [[S:%.*]] = sub i8 0, [[Y:%.*]]461; CHECK-NEXT: [[O:%.*]] = or i8 [[X:%.*]], [[S]]462; CHECK-NEXT: call void @use8(i8 [[O]])463; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[O]], -1464; CHECK-NEXT: ret i8 [[NOT]]465;466 %s = sub i8 0, %y467 %o = or i8 %s, %x468 call void @use8(i8 %o)469 %not = xor i8 %o, -1470 ret i8 %not471}472 473define i1 @not_select_bool(i1 %x, i1 %y, i1 %z) {474; CHECK-LABEL: @not_select_bool(475; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 [[Z:%.*]]476; CHECK-NEXT: [[R:%.*]] = xor i1 [[SEL]], true477; CHECK-NEXT: ret i1 [[R]]478;479 %sel = select i1 %x, i1 %y, i1 %z480 %r = xor i1 %sel, true481 ret i1 %r482}483 484define i1 @not_select_bool_const1(i1 %x, i1 %y) {485; CHECK-LABEL: @not_select_bool_const1(486; CHECK-NEXT: [[Y_NOT:%.*]] = xor i1 [[Y:%.*]], true487; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 [[Y_NOT]], i1 false488; CHECK-NEXT: ret i1 [[R]]489;490 %sel = select i1 %x, i1 %y, i1 true491 %r = xor i1 %sel, true492 ret i1 %r493}494 495define i1 @not_select_bool_const2(i1 %x, i1 %y) {496; CHECK-LABEL: @not_select_bool_const2(497; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false498; CHECK-NEXT: [[R:%.*]] = xor i1 [[SEL]], true499; CHECK-NEXT: ret i1 [[R]]500;501 %sel = select i1 %x, i1 %y, i1 false502 %r = xor i1 %sel, true503 ret i1 %r504}505 506define i1 @not_select_bool_const3(i1 %x, i1 %y) {507; CHECK-LABEL: @not_select_bool_const3(508; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]509; CHECK-NEXT: [[R:%.*]] = xor i1 [[SEL]], true510; CHECK-NEXT: ret i1 [[R]]511;512 %sel = select i1 %x, i1 true, i1 %y513 %r = xor i1 %sel, true514 ret i1 %r515}516 517define i1 @not_select_bool_const4(i1 %x, i1 %y) {518; CHECK-LABEL: @not_select_bool_const4(519; CHECK-NEXT: [[Y_NOT:%.*]] = xor i1 [[Y:%.*]], true520; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y_NOT]]521; CHECK-NEXT: ret i1 [[R]]522;523 %sel = select i1 %x, i1 false, i1 %y524 %r = xor i1 %sel, true525 ret i1 %r526}527 528define <2 x i1> @not_logicalAnd_not_op0(<2 x i1> %x, <2 x i1> %y) {529; CHECK-LABEL: @not_logicalAnd_not_op0(530; CHECK-NEXT: [[Y_NOT:%.*]] = xor <2 x i1> [[Y:%.*]], splat (i1 true)531; CHECK-NEXT: [[NOTAND:%.*]] = select <2 x i1> [[X:%.*]], <2 x i1> splat (i1 true), <2 x i1> [[Y_NOT]]532; CHECK-NEXT: ret <2 x i1> [[NOTAND]]533;534 %notx = xor <2 x i1> %x, <i1 true, i1 true>535 %and = select <2 x i1> %notx, <2 x i1> %y, <2 x i1> zeroinitializer536 %notand = xor <2 x i1> %and, <i1 true, i1 true>537 ret <2 x i1> %notand538}539 540define i1 @not_logicalAnd_not_op1(i1 %x, i1 %y) {541; CHECK-LABEL: @not_logicalAnd_not_op1(542; CHECK-NEXT: [[NOT_X:%.*]] = xor i1 [[X:%.*]], true543; CHECK-NEXT: [[NOTAND:%.*]] = select i1 [[NOT_X]], i1 true, i1 [[Y:%.*]]544; CHECK-NEXT: ret i1 [[NOTAND]]545;546 %noty = xor i1 %y, true547 %and = select i1 %x, i1 %noty, i1 false548 %notand = xor i1 %and, true549 ret i1 %notand550}551 552define i1 @not_logicalAnd_not_op0_use1(i1 %x, i1 %y) {553; CHECK-LABEL: @not_logicalAnd_not_op0_use1(554; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true555; CHECK-NEXT: call void @use1(i1 [[NOTX]])556; CHECK-NEXT: [[Y_NOT:%.*]] = xor i1 [[Y:%.*]], true557; CHECK-NEXT: [[NOTAND:%.*]] = select i1 [[X]], i1 true, i1 [[Y_NOT]]558; CHECK-NEXT: ret i1 [[NOTAND]]559;560 %notx = xor i1 %x, true561 call void @use1(i1 %notx)562 %and = select i1 %notx, i1 %y, i1 false563 %notand = xor i1 %and, true564 ret i1 %notand565}566 567; negative test568 569define i1 @not_logicalAnd_not_op0_use2(i1 %x, i1 %y) {570; CHECK-LABEL: @not_logicalAnd_not_op0_use2(571; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true572; CHECK-NEXT: [[AND:%.*]] = select i1 [[NOTX]], i1 [[Y:%.*]], i1 false573; CHECK-NEXT: call void @use1(i1 [[AND]])574; CHECK-NEXT: [[NOTAND:%.*]] = xor i1 [[AND]], true575; CHECK-NEXT: ret i1 [[NOTAND]]576;577 %notx = xor i1 %x, true578 %and = select i1 %notx, i1 %y, i1 false579 call void @use1(i1 %and)580 %notand = xor i1 %and, true581 ret i1 %notand582}583 584define <2 x i1> @not_logicalOr_not_op0(<2 x i1> %x, <2 x i1> %y) {585; CHECK-LABEL: @not_logicalOr_not_op0(586; CHECK-NEXT: [[Y_NOT:%.*]] = xor <2 x i1> [[Y:%.*]], splat (i1 true)587; CHECK-NEXT: [[NOTOR:%.*]] = select <2 x i1> [[X:%.*]], <2 x i1> [[Y_NOT]], <2 x i1> zeroinitializer588; CHECK-NEXT: ret <2 x i1> [[NOTOR]]589;590 %notx = xor <2 x i1> %x, <i1 true, i1 true>591 %or = select <2 x i1> %notx, <2 x i1> <i1 true, i1 true>, <2 x i1> %y592 %notor = xor <2 x i1> %or, <i1 true, i1 true>593 ret <2 x i1> %notor594}595 596define i1 @not_logicalOr_not_op1(i1 %x, i1 %y) {597; CHECK-LABEL: @not_logicalOr_not_op1(598; CHECK-NEXT: [[NOT_X:%.*]] = xor i1 [[X:%.*]], true599; CHECK-NEXT: [[NOTOR:%.*]] = select i1 [[NOT_X]], i1 [[Y:%.*]], i1 false600; CHECK-NEXT: ret i1 [[NOTOR]]601;602 %noty = xor i1 %y, true603 %or = select i1 %x, i1 true, i1 %noty604 %notor = xor i1 %or, true605 ret i1 %notor606}607 608define i1 @not_logicalOr_not_op0_use1(i1 %x, i1 %y) {609; CHECK-LABEL: @not_logicalOr_not_op0_use1(610; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true611; CHECK-NEXT: call void @use1(i1 [[NOTX]])612; CHECK-NEXT: [[Y_NOT:%.*]] = xor i1 [[Y:%.*]], true613; CHECK-NEXT: [[NOTOR:%.*]] = select i1 [[X]], i1 [[Y_NOT]], i1 false614; CHECK-NEXT: ret i1 [[NOTOR]]615;616 %notx = xor i1 %x, true617 call void @use1(i1 %notx)618 %or = select i1 %notx, i1 true, i1 %y619 %notor = xor i1 %or, true620 ret i1 %notor621}622 623; negative test624 625define i1 @not_logicalOr_not_op0_use2(i1 %x, i1 %y) {626; CHECK-LABEL: @not_logicalOr_not_op0_use2(627; CHECK-NEXT: [[NOTX:%.*]] = xor i1 [[X:%.*]], true628; CHECK-NEXT: [[OR:%.*]] = select i1 [[NOTX]], i1 true, i1 [[Y:%.*]]629; CHECK-NEXT: call void @use1(i1 [[OR]])630; CHECK-NEXT: [[NOTOR:%.*]] = xor i1 [[OR]], true631; CHECK-NEXT: ret i1 [[NOTOR]]632;633 %notx = xor i1 %x, true634 %or = select i1 %notx, i1 true, i1 %y635 call void @use1(i1 %or)636 %notor = xor i1 %or, true637 ret i1 %notor638}639 640; canonicalize 'not' ahead of casts of a bool value641 642define <2 x i64> @bitcast_to_wide_elts_sext_bool(<4 x i1> %b) {643; CHECK-LABEL: @bitcast_to_wide_elts_sext_bool(644; CHECK-NEXT: [[TMP1:%.*]] = xor <4 x i1> [[B:%.*]], splat (i1 true)645; CHECK-NEXT: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i32>646; CHECK-NEXT: [[NOT:%.*]] = bitcast <4 x i32> [[TMP2]] to <2 x i64>647; CHECK-NEXT: ret <2 x i64> [[NOT]]648;649 %sext = sext <4 x i1> %b to <4 x i32>650 %bc = bitcast <4 x i32> %sext to <2 x i64>651 %not = xor <2 x i64> %bc, <i64 -1, i64 -1>652 ret <2 x i64> %not653}654 655define <8 x i16> @bitcast_to_narrow_elts_sext_bool(<4 x i1> %b) {656; CHECK-LABEL: @bitcast_to_narrow_elts_sext_bool(657; CHECK-NEXT: [[TMP1:%.*]] = xor <4 x i1> [[B:%.*]], splat (i1 true)658; CHECK-NEXT: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i32>659; CHECK-NEXT: [[NOT:%.*]] = bitcast <4 x i32> [[TMP2]] to <8 x i16>660; CHECK-NEXT: ret <8 x i16> [[NOT]]661;662 %sext = sext <4 x i1> %b to <4 x i32>663 %bc = bitcast <4 x i32> %sext to <8 x i16>664 %not = xor <8 x i16> %bc, <i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1, i16 -1>665 ret <8 x i16> %not666}667 668define <2 x i16> @bitcast_to_vec_sext_bool(i1 %b) {669; CHECK-LABEL: @bitcast_to_vec_sext_bool(670; CHECK-NEXT: [[TMP1:%.*]] = xor i1 [[B:%.*]], true671; CHECK-NEXT: [[TMP2:%.*]] = sext i1 [[TMP1]] to i32672; CHECK-NEXT: [[NOT:%.*]] = bitcast i32 [[TMP2]] to <2 x i16>673; CHECK-NEXT: ret <2 x i16> [[NOT]]674;675 %sext = sext i1 %b to i32676 %bc = bitcast i32 %sext to <2 x i16>677 %not = xor <2 x i16> %bc, <i16 -1, i16 -1>678 ret <2 x i16> %not679}680 681define i128 @bitcast_to_scalar_sext_bool(<4 x i1> %b) {682; CHECK-LABEL: @bitcast_to_scalar_sext_bool(683; CHECK-NEXT: [[TMP1:%.*]] = xor <4 x i1> [[B:%.*]], splat (i1 true)684; CHECK-NEXT: [[TMP2:%.*]] = sext <4 x i1> [[TMP1]] to <4 x i32>685; CHECK-NEXT: [[NOT:%.*]] = bitcast <4 x i32> [[TMP2]] to i128686; CHECK-NEXT: ret i128 [[NOT]]687;688 %sext = sext <4 x i1> %b to <4 x i32>689 %bc = bitcast <4 x i32> %sext to i128690 %not = xor i128 %bc, -1691 ret i128 %not692}693 694; negative test695 696define <2 x i4> @bitcast_to_vec_sext_bool_use1(i1 %b) {697; CHECK-LABEL: @bitcast_to_vec_sext_bool_use1(698; CHECK-NEXT: [[SEXT:%.*]] = sext i1 [[B:%.*]] to i8699; CHECK-NEXT: call void @use8(i8 [[SEXT]])700; CHECK-NEXT: [[BC:%.*]] = bitcast i8 [[SEXT]] to <2 x i4>701; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i4> [[BC]], splat (i4 -1)702; CHECK-NEXT: ret <2 x i4> [[NOT]]703;704 %sext = sext i1 %b to i8705 call void @use8(i8 %sext)706 %bc = bitcast i8 %sext to <2 x i4>707 %not = xor <2 x i4> %bc, <i4 -1, i4 -1>708 ret <2 x i4> %not709}710 711; negative test712 713define i8 @bitcast_to_scalar_sext_bool_use2(<4 x i1> %b) {714; CHECK-LABEL: @bitcast_to_scalar_sext_bool_use2(715; CHECK-NEXT: [[SEXT:%.*]] = sext <4 x i1> [[B:%.*]] to <4 x i2>716; CHECK-NEXT: [[BC:%.*]] = bitcast <4 x i2> [[SEXT]] to i8717; CHECK-NEXT: call void @use8(i8 [[BC]])718; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[BC]], -1719; CHECK-NEXT: ret i8 [[NOT]]720;721 %sext = sext <4 x i1> %b to <4 x i2>722 %bc = bitcast <4 x i2> %sext to i8723 call void @use8(i8 %bc)724 %not = xor i8 %bc, -1725 ret i8 %not726}727 728; PR74302729define i1 @invert_both_cmp_operands_add(i32 %a, i32 %b) {730; CHECK-LABEL: @invert_both_cmp_operands_add(731; CHECK-NEXT: entry:732; CHECK-NEXT: [[TMP0:%.*]] = sub i32 [[A:%.*]], [[B:%.*]]733; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[TMP0]], -1734; CHECK-NEXT: ret i1 [[CMP]]735;736entry:737 %not.a = xor i32 %a, -1738 %add = add i32 %b, %not.a739 %cmp = icmp sgt i32 %add, 0740 ret i1 %cmp741}742 743define i1 @invert_both_cmp_operands_sub(i32 %a, i32 %b) {744; CHECK-LABEL: @invert_both_cmp_operands_sub(745; CHECK-NEXT: entry:746; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[A:%.*]], [[B:%.*]]747; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[TMP0]], -43748; CHECK-NEXT: ret i1 [[CMP]]749;750entry:751 %not.a = xor i32 %a, -1752 %add = sub i32 %not.a, %b753 %cmp = icmp ult i32 %add, 42754 ret i1 %cmp755}756 757define i1 @invert_both_cmp_operands_complex(i1 %x, i32 %a, i32 %b, i32 %c) {758; CHECK-LABEL: @invert_both_cmp_operands_complex(759; CHECK-NEXT: entry:760; CHECK-NEXT: [[TMP0:%.*]] = sub i32 [[A:%.*]], [[C:%.*]]761; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[X:%.*]], i32 [[TMP0]], i32 [[B:%.*]]762; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[TMP1]], [[C]]763; CHECK-NEXT: ret i1 [[CMP]]764;765entry:766 %not.a = xor i32 %a, -1767 %not.b = xor i32 %b, -1768 %not.c = xor i32 %c, -1769 %add = add i32 %c, %not.a770 %select = select i1 %x, i32 %add, i32 %not.b771 %cmp = icmp sle i32 %select, %not.c772 ret i1 %cmp773}774 775define i32 @test_sext(i32 %a, i32 %b){776; CHECK-LABEL: @test_sext(777; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i32 [[A:%.*]], 0778; CHECK-NEXT: [[TMP2:%.*]] = sext i1 [[TMP1]] to i32779; CHECK-NEXT: [[NOT:%.*]] = sub i32 [[TMP2]], [[B:%.*]]780; CHECK-NEXT: ret i32 [[NOT]]781;782 %cmp = icmp eq i32 %a, 0783 %sext = sext i1 %cmp to i32784 %add = add i32 %b, %sext785 %not = xor i32 %add, -1786 ret i32 %not787}788 789define <2 x i32> @test_sext_vec(<2 x i32> %a, <2 x i32> %b){790; CHECK-LABEL: @test_sext_vec(791; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <2 x i32> [[A:%.*]], zeroinitializer792; CHECK-NEXT: [[TMP2:%.*]] = sext <2 x i1> [[TMP1]] to <2 x i32>793; CHECK-NEXT: [[NOT:%.*]] = sub <2 x i32> [[TMP2]], [[B:%.*]]794; CHECK-NEXT: ret <2 x i32> [[NOT]]795;796 %cmp = icmp eq <2 x i32> %a, zeroinitializer797 %sext = sext <2 x i1> %cmp to <2 x i32>798 %add = add <2 x i32> %b, %sext799 %not = xor <2 x i32> %add, <i32 -1, i32 -1>800 ret <2 x i32> %not801}802 803define i64 @test_zext_nneg(i32 %c1, i64 %c2, i64 %c3){804; CHECK-LABEL: @test_zext_nneg(805; CHECK-NEXT: [[DOTNEG:%.*]] = add i64 [[C2:%.*]], -4806; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[C1:%.*]] to i64807; CHECK-NEXT: [[TMP2:%.*]] = sub i64 [[TMP1]], [[C3:%.*]]808; CHECK-NEXT: [[SUB:%.*]] = add i64 [[DOTNEG]], [[TMP2]]809; CHECK-NEXT: ret i64 [[SUB]]810;811 %not = xor i32 %c1, -1812 %conv = zext nneg i32 %not to i64813 %add1 = add i64 %c2, -5814 %add2 = add i64 %conv, %c3815 %sub = sub i64 %add1, %add2816 ret i64 %sub817}818 819define i8 @test_trunc(i8 %a){820; CHECK-LABEL: @test_trunc(821; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i8 [[A:%.*]], 0822; CHECK-NEXT: [[NOT:%.*]] = sext i1 [[TMP1]] to i8823; CHECK-NEXT: ret i8 [[NOT]]824;825 %zext = zext i8 %a to i32826 %sub = add nsw i32 %zext, -1827 %shr = ashr i32 %sub, 31828 %conv = trunc i32 %shr to i8829 %not = xor i8 %conv, -1830 ret i8 %not831}832 833define <2 x i8> @test_trunc_vec(<2 x i8> %a){834; CHECK-LABEL: @test_trunc_vec(835; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <2 x i8> [[A:%.*]], zeroinitializer836; CHECK-NEXT: [[NOT:%.*]] = sext <2 x i1> [[TMP1]] to <2 x i8>837; CHECK-NEXT: ret <2 x i8> [[NOT]]838;839 %zext = zext <2 x i8> %a to <2 x i32>840 %sub = add nsw <2 x i32> %zext, <i32 -1, i32 -1>841 %shr = ashr <2 x i32> %sub, <i32 31, i32 31>842 %conv = trunc <2 x i32> %shr to <2 x i8>843 %not = xor <2 x i8> %conv, <i8 -1, i8 -1>844 ret <2 x i8> %not845}846 847; Negative tests848 849define i32 @test_zext(i32 %a, i32 %b){850; CHECK-LABEL: @test_zext(851; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], 0852; CHECK-NEXT: [[SEXT:%.*]] = zext i1 [[CMP]] to i32853; CHECK-NEXT: [[ADD:%.*]] = add i32 [[B:%.*]], [[SEXT]]854; CHECK-NEXT: [[NOT:%.*]] = xor i32 [[ADD]], -1855; CHECK-NEXT: ret i32 [[NOT]]856;857 %cmp = icmp eq i32 %a, 0858 %sext = zext i1 %cmp to i32859 %add = add i32 %b, %sext860 %not = xor i32 %add, -1861 ret i32 %not862}863 864define void @test_invert_demorgan_or(i32 %a, i32 %b, i1 %cond) {865; CHECK-LABEL: @test_invert_demorgan_or(866; CHECK-NEXT: entry:867; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[A:%.*]], 0868; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[B:%.*]], 0869; CHECK-NEXT: [[OR_NOT1:%.*]] = and i1 [[CMP1]], [[CMP2]]870; CHECK-NEXT: [[MERGE_NOT:%.*]] = and i1 [[OR_NOT1]], [[COND:%.*]]871; CHECK-NEXT: br i1 [[MERGE_NOT]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]872; CHECK: if.then:873; CHECK-NEXT: call void @f1()874; CHECK-NEXT: unreachable875; CHECK: if.else:876; CHECK-NEXT: call void @f2()877; CHECK-NEXT: unreachable878;879entry:880 %cmp1 = icmp eq i32 %a, 0881 %cmp2 = icmp ne i32 %b, 0882 %or = or i1 %cmp1, %cmp2883 %not = xor i1 %cond, true884 %merge = or i1 %not, %or885 br i1 %merge, label %if.then, label %if.else886if.then:887 call void @f1()888 unreachable889if.else:890 call void @f2()891 unreachable892}893 894define i1 @test_invert_demorgan_or2(i64 %a, i64 %b, i64 %c) {895; CHECK-LABEL: @test_invert_demorgan_or2(896; CHECK-NEXT: [[CMP1:%.*]] = icmp ult i64 [[A:%.*]], 24897; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i64 [[B:%.*]], 60898; CHECK-NEXT: [[OR1_NOT1:%.*]] = and i1 [[CMP1]], [[CMP2]]899; CHECK-NEXT: [[CMP3:%.*]] = icmp ult i64 [[C:%.*]], 60900; CHECK-NEXT: [[OR2_NOT:%.*]] = and i1 [[OR1_NOT1]], [[CMP3]]901; CHECK-NEXT: ret i1 [[OR2_NOT]]902;903 %cmp1 = icmp ugt i64 %a, 23904 %cmp2 = icmp ugt i64 %b, 59905 %or1 = or i1 %cmp1, %cmp2906 %cmp3 = icmp ugt i64 %c, 59907 %or2 = or i1 %or1, %cmp3908 %not = xor i1 %or2, true909 ret i1 %not910}911 912define i1 @test_invert_demorgan_or3(i32 %a, i32 %b) {913; CHECK-LABEL: @test_invert_demorgan_or3(914; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[A:%.*]], 178206915; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[B:%.*]], -196608916; CHECK-NEXT: [[CMP2:%.*]] = icmp ult i32 [[TMP1]], -1506917; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[B]], -917760918; CHECK-NEXT: [[CMP3:%.*]] = icmp ult i32 [[TMP2]], -716213919; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[B]], -1114112920; CHECK-NEXT: [[CMP4:%.*]] = icmp ult i32 [[TMP3]], -196112921; CHECK-NEXT: [[OR1_NOT2:%.*]] = and i1 [[CMP1]], [[CMP2]]922; CHECK-NEXT: [[OR2_NOT1:%.*]] = and i1 [[OR1_NOT2]], [[CMP3]]923; CHECK-NEXT: [[OR3_NOT:%.*]] = and i1 [[OR2_NOT1]], [[CMP4]]924; CHECK-NEXT: ret i1 [[OR3_NOT]]925;926 %cmp1 = icmp eq i32 %a, 178206927 %v1 = add i32 %b, -195102928 %cmp2 = icmp ult i32 %v1, 1506929 %v2 = add i32 %b, -201547930 %cmp3 = icmp ult i32 %v2, 716213931 %v3 = add i32 %b, -918000932 %cmp4 = icmp ult i32 %v3, 196112933 %or1 = or i1 %cmp1, %cmp2934 %or2 = or i1 %or1, %cmp3935 %or3 = or i1 %or2, %cmp4936 %not = xor i1 %or3, true937 ret i1 %not938}939 940define i1 @test_invert_demorgan_logical_or(i64 %x, i64 %y) {941; CHECK-LABEL: @test_invert_demorgan_logical_or(942; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i64 [[X:%.*]], 27943; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i64 [[Y:%.*]], 0944; CHECK-NEXT: [[SEL_NOT1:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false945; CHECK-NEXT: [[CMP3:%.*]] = icmp ne i64 [[X]], 0946; CHECK-NEXT: [[OR_NOT:%.*]] = and i1 [[CMP3]], [[SEL_NOT1]]947; CHECK-NEXT: ret i1 [[OR_NOT]]948;949 %cmp1 = icmp eq i64 %x, 27950 %cmp2 = icmp eq i64 %y, 0951 %sel = select i1 %cmp1, i1 true, i1 %cmp2952 %cmp3 = icmp eq i64 %x, 0953 %or = or i1 %cmp3, %sel954 %not = xor i1 %or, true955 ret i1 %not956}957 958define i1 @test_invert_demorgan_and(i32 %a, i32 %b, i1 %cond) {959; CHECK-LABEL: @test_invert_demorgan_and(960; CHECK-NEXT: entry:961; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[A:%.*]], 0962; CHECK-NEXT: [[CMP2:%.*]] = icmp eq i32 [[B:%.*]], 0963; CHECK-NEXT: [[AND_NOT1:%.*]] = or i1 [[CMP1]], [[CMP2]]964; CHECK-NEXT: [[MERGE_NOT:%.*]] = or i1 [[AND_NOT1]], [[COND:%.*]]965; CHECK-NEXT: br i1 [[MERGE_NOT]], label [[IF_ELSE:%.*]], label [[IF_THEN:%.*]]966; CHECK: if.then:967; CHECK-NEXT: call void @f1()968; CHECK-NEXT: unreachable969; CHECK: if.else:970; CHECK-NEXT: call void @f2()971; CHECK-NEXT: unreachable972;973entry:974 %cmp1 = icmp eq i32 %a, 0975 %cmp2 = icmp ne i32 %b, 0976 %and = and i1 %cmp1, %cmp2977 %not = xor i1 %cond, true978 %merge = and i1 %not, %and979 br i1 %merge, label %if.then, label %if.else980if.then:981 call void @f1()982 unreachable983if.else:984 call void @f2()985 unreachable986}987 988define i64 @test_invert_demorgan_and2(i64 %x) {989; CHECK-LABEL: @test_invert_demorgan_and2(990; CHECK-NEXT: [[TMP1:%.*]] = sub i64 0, [[X:%.*]]991; CHECK-NEXT: [[SUB:%.*]] = or i64 [[TMP1]], -9223372036854775808992; CHECK-NEXT: ret i64 [[SUB]]993;994 %add = add i64 %x, 9223372036854775807995 %and = and i64 %add, 9223372036854775807996 %sub = xor i64 %and, -1997 ret i64 %sub998}999 1000define i1 @test_invert_demorgan_and3(i32 %a, i32 %b) {1001; CHECK-LABEL: @test_invert_demorgan_and3(1002; CHECK-NEXT: [[TMP1:%.*]] = sub i32 [[A:%.*]], [[B:%.*]]1003; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 40951004; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[TMP2]], 40951005; CHECK-NEXT: ret i1 [[CMP]]1006;1007 %not = xor i32 %a, -11008 %add = add i32 %b, %not1009 %and = and i32 %add, 40951010 %cmp = icmp eq i32 %and, 01011 ret i1 %cmp1012}1013 1014define i1 @test_invert_demorgan_logical_and(i64 %x, i64 %y) {1015; CHECK-LABEL: @test_invert_demorgan_logical_and(1016; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i64 [[X:%.*]], 271017; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i64 [[Y:%.*]], 01018; CHECK-NEXT: [[SEL_NOT1:%.*]] = select i1 [[CMP1]], i1 true, i1 [[CMP2]]1019; CHECK-NEXT: [[CMP3:%.*]] = icmp ne i64 [[X]], 01020; CHECK-NEXT: [[OR_NOT:%.*]] = and i1 [[CMP3]], [[SEL_NOT1]]1021; CHECK-NEXT: ret i1 [[OR_NOT]]1022;1023 %cmp1 = icmp eq i64 %x, 271024 %cmp2 = icmp eq i64 %y, 01025 %sel = select i1 %cmp1, i1 %cmp2, i1 false1026 %cmp3 = icmp eq i64 %x, 01027 %or = or i1 %cmp3, %sel1028 %not = xor i1 %or, true1029 ret i1 %not1030}1031 1032define i1 @test_invert_demorgan_and_multiuse(i32 %a, i32 %b, i1 %cond) {1033; CHECK-LABEL: @test_invert_demorgan_and_multiuse(1034; CHECK-NEXT: entry:1035; CHECK-NEXT: [[CMP1:%.*]] = icmp eq i32 [[A:%.*]], 01036; CHECK-NEXT: call void @use1(i1 [[CMP1]])1037; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i32 [[B:%.*]], 01038; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[COND:%.*]], true1039; CHECK-NEXT: [[TMP0:%.*]] = and i1 [[CMP2]], [[NOT]]1040; CHECK-NEXT: [[MERGE:%.*]] = and i1 [[TMP0]], [[CMP1]]1041; CHECK-NEXT: br i1 [[MERGE]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]1042; CHECK: if.then:1043; CHECK-NEXT: call void @f1()1044; CHECK-NEXT: unreachable1045; CHECK: if.else:1046; CHECK-NEXT: call void @f2()1047; CHECK-NEXT: unreachable1048;1049entry:1050 %cmp1 = icmp eq i32 %a, 01051 call void @use1(i1 %cmp1)1052 %cmp2 = icmp ne i32 %b, 01053 %and = and i1 %cmp1, %cmp21054 %not = xor i1 %cond, true1055 %merge = and i1 %not, %and1056 br i1 %merge, label %if.then, label %if.else1057if.then:1058 call void @f1()1059 unreachable1060if.else:1061 call void @f2()1062 unreachable1063}1064 1065define i8 @invert_bitcasted_icmp(<8 x i32> %a, <8 x i32> %b) {1066; CHECK-LABEL: @invert_bitcasted_icmp(1067; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <8 x i32> [[A:%.*]], [[B:%.*]]1068; CHECK-NEXT: [[MASK_AS_INT:%.*]] = bitcast <8 x i1> [[CMP]] to i81069; CHECK-NEXT: ret i8 [[MASK_AS_INT]]1070;1071 %cmp = icmp sle <8 x i32> %a, %b1072 %mask.as.int = bitcast <8 x i1> %cmp to i81073 %not = xor i8 %mask.as.int, 2551074 ret i8 %not1075}1076 1077define i8 @invert_bitcasted_icmp_samesign(<8 x i32> %a, <8 x i32> %b) {1078; CHECK-LABEL: @invert_bitcasted_icmp_samesign(1079; CHECK-NEXT: [[CMP:%.*]] = icmp samesign sgt <8 x i32> [[A:%.*]], [[B:%.*]]1080; CHECK-NEXT: [[MASK_AS_INT:%.*]] = bitcast <8 x i1> [[CMP]] to i81081; CHECK-NEXT: ret i8 [[MASK_AS_INT]]1082;1083 %cmp = icmp samesign sle <8 x i32> %a, %b1084 %mask.as.int = bitcast <8 x i1> %cmp to i81085 %not = xor i8 %mask.as.int, 2551086 ret i8 %not1087}1088 1089define i8 @invert_bitcasted_icmp_multi_use_1(<8 x i32> %a, <8 x i32> %b) {1090; CHECK-LABEL: @invert_bitcasted_icmp_multi_use_1(1091; CHECK-NEXT: [[CMP:%.*]] = icmp sle <8 x i32> [[A:%.*]], [[B:%.*]]1092; CHECK-NEXT: call void (...) @llvm.fake.use(<8 x i1> [[CMP]])1093; CHECK-NEXT: [[MASK_AS_INT:%.*]] = bitcast <8 x i1> [[CMP]] to i81094; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[MASK_AS_INT]], -11095; CHECK-NEXT: ret i8 [[NOT]]1096;1097 %cmp = icmp sle <8 x i32> %a, %b1098 call void (...) @llvm.fake.use(<8 x i1> %cmp)1099 %mask.as.int = bitcast <8 x i1> %cmp to i81100 %not = xor i8 %mask.as.int, -11101 ret i8 %not1102}1103 1104define i8 @invert_bitcasted_icmp_multi_use_2(<8 x i32> %a, <8 x i32> %b) {1105; CHECK-LABEL: @invert_bitcasted_icmp_multi_use_2(1106; CHECK-NEXT: [[CMP:%.*]] = icmp sle <8 x i32> [[A:%.*]], [[B:%.*]]1107; CHECK-NEXT: [[MASK_AS_INT:%.*]] = bitcast <8 x i1> [[CMP]] to i81108; CHECK-NEXT: call void (...) @llvm.fake.use(i8 [[MASK_AS_INT]])1109; CHECK-NEXT: [[NOT:%.*]] = xor i8 [[MASK_AS_INT]], -11110; CHECK-NEXT: ret i8 [[NOT]]1111;1112 %cmp = icmp sle <8 x i32> %a, %b1113 %mask.as.int = bitcast <8 x i1> %cmp to i81114 call void (...) @llvm.fake.use(i8 %mask.as.int)1115 %not = xor i8 %mask.as.int, -11116 ret i8 %not1117}1118 1119define i8 @invert_bitcasted_fcmp(<8 x float> %a, <8 x float> %b) {1120; CHECK-LABEL: @invert_bitcasted_fcmp(1121; CHECK-NEXT: [[CMP:%.*]] = fcmp uge <8 x float> [[A:%.*]], [[B:%.*]]1122; CHECK-NEXT: [[MASK_AS_INT:%.*]] = bitcast <8 x i1> [[CMP]] to i81123; CHECK-NEXT: ret i8 [[MASK_AS_INT]]1124;1125 %cmp = fcmp olt <8 x float> %a, %b1126 %mask.as.int = bitcast <8 x i1> %cmp to i81127 %not = xor i8 %mask.as.int, 2551128 ret i8 %not1129}1130 1131define i8 @invert_bitcasted_fcmp_fast(<8 x float> %a, <8 x float> %b) {1132; CHECK-LABEL: @invert_bitcasted_fcmp_fast(1133; CHECK-NEXT: [[CMP:%.*]] = fcmp fast uge <8 x float> [[A:%.*]], [[B:%.*]]1134; CHECK-NEXT: [[MASK_AS_INT:%.*]] = bitcast <8 x i1> [[CMP]] to i81135; CHECK-NEXT: ret i8 [[MASK_AS_INT]]1136;1137 %cmp = fcmp fast olt <8 x float> %a, %b1138 %mask.as.int = bitcast <8 x i1> %cmp to i81139 %not = xor i8 %mask.as.int, 2551140 ret i8 %not1141}1142