@@ -335,7 +335,7 @@ define i32 @sub_sel_op1_use(i1 %b) {
335335
336336define float @fadd_sel_op0 (i1 %b , float %x ) {
337337; CHECK-LABEL: @fadd_sel_op0(
338- ; CHECK-NEXT: [[R:%.*]] = select nnan i1 [[B:%.*]], float 0xFFF0000000000000, float 0x7FF0000000000000
338+ ; CHECK-NEXT: [[R:%.*]] = select i1 [[B:%.*]], float 0xFFF0000000000000, float 0x7FF0000000000000
339339; CHECK-NEXT: ret float [[R]]
340340;
341341 %s = select i1 %b , float 0xFFF0000000000000 , float 0x7FF0000000000000
@@ -403,3 +403,188 @@ define i32 @ashr_sel_op1_use(i1 %b) {
403403 %r = ashr i32 -2 , %s
404404 ret i32 %r
405405}
406+
407+ define i8 @commonArgWithOr0 (i1 %arg0 ) {
408+ ; CHECK-LABEL: @commonArgWithOr0(
409+ ; CHECK-NEXT: [[V0:%.*]] = zext i1 [[ARG0:%.*]] to i8
410+ ; CHECK-NEXT: [[V1:%.*]] = select i1 [[ARG0]], i8 0, i8 8
411+ ; CHECK-NEXT: [[V2:%.*]] = or disjoint i8 [[V1]], [[V0]]
412+ ; CHECK-NEXT: [[V3:%.*]] = or disjoint i8 [[V2]], 16
413+ ; CHECK-NEXT: ret i8 [[V3]]
414+ ;
415+ %v0 = zext i1 %arg0 to i8
416+ %v1 = select i1 %arg0 , i8 0 , i8 8
417+ %v2 = or i8 %v1 , %v0
418+ %v3 = or i8 %v2 , 16
419+ ret i8 %v3
420+ }
421+
422+ define i8 @commonArgWithOr1 (i1 %arg0 ) {
423+ ; CHECK-LABEL: @commonArgWithOr1(
424+ ; CHECK-NEXT: [[V3:%.*]] = select i1 [[ARG0:%.*]], i8 17, i8 23
425+ ; CHECK-NEXT: ret i8 [[V3]]
426+ ;
427+ %v0 = zext i1 %arg0 to i8
428+ %v1 = select i1 %arg0 , i8 1 , i8 7
429+ %v2 = or i8 %v1 , %v0
430+ %v3 = or i8 %v2 , 16
431+ ret i8 %v3
432+ }
433+
434+ define i8 @commonArgWithOr2 (i1 %arg0 ) {
435+ ; CHECK-LABEL: @commonArgWithOr2(
436+ ; CHECK-NEXT: [[V0:%.*]] = zext i1 [[ARG0:%.*]] to i8
437+ ; CHECK-NEXT: [[V1:%.*]] = select i1 [[ARG0]], i8 5, i8 42
438+ ; CHECK-NEXT: [[V2:%.*]] = or i8 [[V1]], [[V0]]
439+ ; CHECK-NEXT: [[V3:%.*]] = or disjoint i8 [[V2]], 16
440+ ; CHECK-NEXT: ret i8 [[V3]]
441+ ;
442+ %v0 = zext i1 %arg0 to i8
443+ %v1 = select i1 %arg0 , i8 21 , i8 42
444+ %v2 = or i8 %v1 , %v0
445+ %v3 = or i8 %v2 , 16
446+ ret i8 %v3
447+ }
448+
449+ define i8 @commonArgWithAnd0 (i1 %arg0 ) {
450+ ; CHECK-LABEL: @commonArgWithAnd0(
451+ ; CHECK-NEXT: ret i8 16
452+ ;
453+ %v0 = zext i1 %arg0 to i8
454+ %v1 = select i1 %arg0 , i8 0 , i8 8
455+ %v2 = and i8 %v1 , %v0
456+ %v3 = or i8 %v2 , 16
457+ ret i8 %v3
458+ }
459+
460+ define i8 @commonArgWithAnd1 (i1 %arg0 ) {
461+ ; CHECK-LABEL: @commonArgWithAnd1(
462+ ; CHECK-NEXT: ret i8 16
463+ ;
464+ %v0 = zext i1 %arg0 to i8
465+ %v1 = select i1 %arg0 , i8 8 , i8 1
466+ %v2 = and i8 %v1 , %v0
467+ %v3 = or i8 %v2 , 16
468+ ret i8 %v3
469+ }
470+
471+ define i8 @commonArgWithAnd2 (i1 %arg0 ) {
472+ ; CHECK-LABEL: @commonArgWithAnd2(
473+ ; CHECK-NEXT: [[V2:%.*]] = zext i1 [[ARG0:%.*]] to i8
474+ ; CHECK-NEXT: [[V3:%.*]] = or disjoint i8 [[V2]], 16
475+ ; CHECK-NEXT: ret i8 [[V3]]
476+ ;
477+ %v0 = zext i1 %arg0 to i8
478+ %v1 = select i1 %arg0 , i8 1 , i8 7
479+ %v2 = and i8 %v1 , %v0
480+ %v3 = or i8 %v2 , 16
481+ ret i8 %v3
482+ }
483+
484+ define i8 @commonArgWithAnd3 (i1 %arg0 ) {
485+ ; CHECK-LABEL: @commonArgWithAnd3(
486+ ; CHECK-NEXT: [[V2:%.*]] = zext i1 [[ARG0:%.*]] to i8
487+ ; CHECK-NEXT: [[V3:%.*]] = or disjoint i8 [[V2]], 16
488+ ; CHECK-NEXT: ret i8 [[V3]]
489+ ;
490+ %v0 = zext i1 %arg0 to i8
491+ %v1 = select i1 %arg0 , i8 21 , i8 42
492+ %v2 = and i8 %v1 , %v0
493+ %v3 = or i8 %v2 , 16
494+ ret i8 %v3
495+ }
496+
497+ define i8 @commonArgWithXor0 (i1 %arg0 ) {
498+ ; CHECK-LABEL: @commonArgWithXor0(
499+ ; CHECK-NEXT: [[V0:%.*]] = zext i1 [[ARG0:%.*]] to i8
500+ ; CHECK-NEXT: [[V1:%.*]] = select i1 [[ARG0]], i8 0, i8 8
501+ ; CHECK-NEXT: [[V2:%.*]] = or disjoint i8 [[V1]], [[V0]]
502+ ; CHECK-NEXT: [[V3:%.*]] = or disjoint i8 [[V2]], 16
503+ ; CHECK-NEXT: ret i8 [[V3]]
504+ ;
505+ %v0 = zext i1 %arg0 to i8
506+ %v1 = select i1 %arg0 , i8 0 , i8 8
507+ %v2 = xor i8 %v1 , %v0
508+ %v3 = or i8 %v2 , 16
509+ ret i8 %v3
510+ }
511+
512+ define i8 @commonArgWithXor1 (i1 %arg0 ) {
513+ ; CHECK-LABEL: @commonArgWithXor1(
514+ ; CHECK-NEXT: [[V0:%.*]] = zext i1 [[ARG0:%.*]] to i8
515+ ; CHECK-NEXT: [[V1:%.*]] = select i1 [[ARG0]], i8 9, i8 1
516+ ; CHECK-NEXT: [[V2:%.*]] = xor i8 [[V1]], [[V0]]
517+ ; CHECK-NEXT: ret i8 [[V2]]
518+ ;
519+ %v0 = zext i1 %arg0 to i8
520+ %v1 = select i1 %arg0 , i8 9 , i8 1
521+ %v2 = xor i8 %v1 , %v0
522+ ret i8 %v2
523+ }
524+
525+ define i8 @commonArgWithXor2 (i1 %arg0 ) {
526+ ; CHECK-LABEL: @commonArgWithXor2(
527+ ; CHECK-NEXT: [[V0:%.*]] = zext i1 [[ARG0:%.*]] to i8
528+ ; CHECK-NEXT: [[V1:%.*]] = select i1 [[ARG0]], i8 1, i8 7
529+ ; CHECK-NEXT: [[V2:%.*]] = xor i8 [[V1]], [[V0]]
530+ ; CHECK-NEXT: [[V3:%.*]] = or disjoint i8 [[V2]], 16
531+ ; CHECK-NEXT: ret i8 [[V3]]
532+ ;
533+ %v0 = zext i1 %arg0 to i8
534+ %v1 = select i1 %arg0 , i8 1 , i8 7
535+ %v2 = xor i8 %v1 , %v0
536+ %v3 = or i8 %v2 , 16
537+ ret i8 %v3
538+ }
539+
540+ define i8 @commonArgWithXor3 (i1 %arg0 ) {
541+ ; CHECK-LABEL: @commonArgWithXor3(
542+ ; CHECK-NEXT: [[V0:%.*]] = zext i1 [[ARG0:%.*]] to i8
543+ ; CHECK-NEXT: [[V1:%.*]] = select i1 [[ARG0]], i8 5, i8 45
544+ ; CHECK-NEXT: [[V2:%.*]] = xor i8 [[V1]], [[V0]]
545+ ; CHECK-NEXT: [[V3:%.*]] = or disjoint i8 [[V2]], 16
546+ ; CHECK-NEXT: ret i8 [[V3]]
547+ ;
548+ %v0 = zext i1 %arg0 to i8
549+ %v1 = select i1 %arg0 , i8 21 , i8 45
550+ %v2 = xor i8 %v1 , %v0
551+ %v3 = or i8 %v2 , 16
552+ ret i8 %v3
553+ }
554+
555+ define i8 @commonArgWithAdd0 (i1 %arg0 ) {
556+ ; CHECK-LABEL: @commonArgWithAdd0(
557+ ; CHECK-NEXT: [[V3:%.*]] = select i1 [[ARG0:%.*]], i8 22, i8 61
558+ ; CHECK-NEXT: ret i8 [[V3]]
559+ ;
560+ %v0 = zext i1 %arg0 to i8
561+ %v1 = select i1 %arg0 , i8 21 , i8 45
562+ %v2 = add i8 %v1 , %v0
563+ %v3 = or i8 %v2 , 16
564+ ret i8 %v3
565+ }
566+
567+ define i32 @OrSelectIcmpZero (i32 %a , i32 %b ) {
568+ ; CHECK-LABEL: @OrSelectIcmpZero(
569+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], 0
570+ ; CHECK-NEXT: [[OR:%.*]] = select i1 [[CMP]], i32 [[B:%.*]], i32 [[A]]
571+ ; CHECK-NEXT: ret i32 [[OR]]
572+ ;
573+ %cmp = icmp eq i32 %a , 0
574+ %sel = select i1 %cmp , i32 %b , i32 0
575+ %or = or i32 %sel , %a
576+ ret i32 %or
577+ }
578+
579+ define i32 @OrSelectIcmpNonZero (i32 %a , i32 %b ) {
580+ ; CHECK-LABEL: @OrSelectIcmpNonZero(
581+ ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[A:%.*]], 0
582+ ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 [[B:%.*]], i32 42
583+ ; CHECK-NEXT: [[OR:%.*]] = or i32 [[SEL]], [[A]]
584+ ; CHECK-NEXT: ret i32 [[OR]]
585+ ;
586+ %cmp = icmp eq i32 %a , 0
587+ %sel = select i1 %cmp , i32 %b , i32 42
588+ %or = or i32 %sel , %a
589+ ret i32 %or
590+ }
0 commit comments