Skip to content

Commit 95f0d51

Browse files
committedJun 12, 2014
This removes TODO added in http://reviews.llvm.org/D3658
The patch transforms ABS(NABS(X)) -> ABS(X) NABS(ABS(X)) -> NABS(X) Differential Revision: http://reviews.llvm.org/D4040 llvm-svn: 210782
1 parent 4956850 commit 95f0d51

File tree

2 files changed

+489
-2
lines changed

2 files changed

+489
-2
lines changed
 

‎llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -733,8 +733,15 @@ Instruction *InstCombiner::FoldSPFofSPF(Instruction *Inner,
733733
return ReplaceInstUsesWith(Outer, Inner);
734734
}
735735

736-
// TODO: ABS(NABS(X)) -> ABS(X)
737-
// TODO: NABS(ABS(X)) -> NABS(X)
736+
// ABS(NABS(X)) -> ABS(X)
737+
// NABS(ABS(X)) -> NABS(X)
738+
if ((SPF1 == SPF_ABS && SPF2 == SPF_NABS) ||
739+
(SPF1 == SPF_NABS && SPF2 == SPF_ABS)) {
740+
SelectInst *SI = cast<SelectInst>(Inner);
741+
Value *NewSI = Builder->CreateSelect(
742+
SI->getCondition(), SI->getFalseValue(), SI->getTrueValue());
743+
return ReplaceInstUsesWith(Outer, NewSI);
744+
}
738745
return nullptr;
739746
}
740747

‎llvm/test/Transforms/InstCombine/abs_abs.ll

+480
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,483 @@ define i32 @nabs_nabs_x16(i32 %x) {
479479
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
480480
; CHECK-NEXT: ret i32 [[SEL]]
481481
}
482+
483+
define i32 @abs_nabs_x01(i32 %x) {
484+
%cmp = icmp sgt i32 %x, -1
485+
%sub = sub nsw i32 0, %x
486+
%cond = select i1 %cmp, i32 %sub, i32 %x
487+
%cmp1 = icmp sgt i32 %cond, -1
488+
%sub16 = sub nsw i32 0, %cond
489+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
490+
ret i32 %cond18
491+
; CHECK-LABEL: @abs_nabs_x01(
492+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, -1
493+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
494+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
495+
; CHECK-NEXT: ret i32 [[SEL]]
496+
}
497+
498+
define i32 @abs_nabs_x02(i32 %x) {
499+
%cmp = icmp sgt i32 %x, 0
500+
%sub = sub nsw i32 0, %x
501+
%cond = select i1 %cmp, i32 %sub, i32 %x
502+
%cmp1 = icmp sgt i32 %cond, -1
503+
%sub16 = sub nsw i32 0, %cond
504+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
505+
ret i32 %cond18
506+
; CHECK-LABEL: @abs_nabs_x02(
507+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, 0
508+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
509+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
510+
; CHECK-NEXT: ret i32 [[SEL]]
511+
}
512+
513+
define i32 @abs_nabs_x03(i32 %x) {
514+
%cmp = icmp slt i32 %x, 0
515+
%sub = sub nsw i32 0, %x
516+
%cond = select i1 %cmp, i32 %x, i32 %sub
517+
%cmp1 = icmp sgt i32 %cond, -1
518+
%sub16 = sub nsw i32 0, %cond
519+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
520+
ret i32 %cond18
521+
; CHECK-LABEL: @abs_nabs_x03(
522+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 0
523+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
524+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
525+
; CHECK-NEXT: ret i32 [[SEL]]
526+
}
527+
528+
define i32 @abs_nabs_x04(i32 %x) {
529+
%cmp = icmp slt i32 %x, 1
530+
%sub = sub nsw i32 0, %x
531+
%cond = select i1 %cmp, i32 %x, i32 %sub
532+
%cmp1 = icmp sgt i32 %cond, -1
533+
%sub16 = sub nsw i32 0, %cond
534+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
535+
ret i32 %cond18
536+
; CHECK-LABEL: @abs_nabs_x04(
537+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 1
538+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
539+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
540+
; CHECK-NEXT: ret i32 [[SEL]]
541+
}
542+
543+
define i32 @abs_nabs_x05(i32 %x) {
544+
%cmp = icmp sgt i32 %x, -1
545+
%sub = sub nsw i32 0, %x
546+
%cond = select i1 %cmp, i32 %sub, i32 %x
547+
%cmp1 = icmp sgt i32 %cond, 0
548+
%sub16 = sub nsw i32 0, %cond
549+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
550+
ret i32 %cond18
551+
; CHECK-LABEL: @abs_nabs_x05(
552+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, -1
553+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
554+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
555+
; CHECK-NEXT: ret i32 [[SEL]]
556+
}
557+
558+
define i32 @abs_nabs_x06(i32 %x) {
559+
%cmp = icmp sgt i32 %x, 0
560+
%sub = sub nsw i32 0, %x
561+
%cond = select i1 %cmp, i32 %sub, i32 %x
562+
%cmp1 = icmp sgt i32 %cond, 0
563+
%sub16 = sub nsw i32 0, %cond
564+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
565+
ret i32 %cond18
566+
; CHECK-LABEL: @abs_nabs_x06(
567+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, 0
568+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
569+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
570+
; CHECK-NEXT: ret i32 [[SEL]]
571+
}
572+
573+
define i32 @abs_nabs_x07(i32 %x) {
574+
%cmp = icmp slt i32 %x, 0
575+
%sub = sub nsw i32 0, %x
576+
%cond = select i1 %cmp, i32 %x, i32 %sub
577+
%cmp1 = icmp sgt i32 %cond, 0
578+
%sub16 = sub nsw i32 0, %cond
579+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
580+
ret i32 %cond18
581+
; CHECK-LABEL: @abs_nabs_x07(
582+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 0
583+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
584+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
585+
; CHECK-NEXT: ret i32 [[SEL]]
586+
}
587+
588+
define i32 @abs_nabs_x08(i32 %x) {
589+
%cmp = icmp slt i32 %x, 1
590+
%sub = sub nsw i32 0, %x
591+
%cond = select i1 %cmp, i32 %x, i32 %sub
592+
%cmp1 = icmp sgt i32 %cond, 0
593+
%sub16 = sub nsw i32 0, %cond
594+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
595+
ret i32 %cond18
596+
; CHECK-LABEL: @abs_nabs_x08(
597+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 1
598+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
599+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
600+
; CHECK-NEXT: ret i32 [[SEL]]
601+
}
602+
603+
define i32 @abs_nabs_x09(i32 %x) {
604+
%cmp = icmp sgt i32 %x, -1
605+
%sub = sub nsw i32 0, %x
606+
%cond = select i1 %cmp, i32 %sub, i32 %x
607+
%cmp1 = icmp slt i32 %cond, 0
608+
%sub9 = sub nsw i32 0, %cond
609+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
610+
ret i32 %cond18
611+
; CHECK-LABEL: @abs_nabs_x09(
612+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, -1
613+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
614+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
615+
; CHECK-NEXT: ret i32 [[SEL]]
616+
}
617+
618+
define i32 @abs_nabs_x10(i32 %x) {
619+
%cmp = icmp sgt i32 %x, 0
620+
%sub = sub nsw i32 0, %x
621+
%cond = select i1 %cmp, i32 %sub, i32 %x
622+
%cmp1 = icmp slt i32 %cond, 0
623+
%sub9 = sub nsw i32 0, %cond
624+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
625+
ret i32 %cond18
626+
; CHECK-LABEL: @abs_nabs_x10(
627+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, 0
628+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
629+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
630+
; CHECK-NEXT: ret i32 [[SEL]]
631+
}
632+
633+
define i32 @abs_nabs_x11(i32 %x) {
634+
%cmp = icmp slt i32 %x, 0
635+
%sub = sub nsw i32 0, %x
636+
%cond = select i1 %cmp, i32 %x, i32 %sub
637+
%cmp1 = icmp slt i32 %cond, 0
638+
%sub9 = sub nsw i32 0, %cond
639+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
640+
ret i32 %cond18
641+
; CHECK-LABEL: @abs_nabs_x11(
642+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 0
643+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
644+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
645+
; CHECK-NEXT: ret i32 [[SEL]]
646+
}
647+
648+
define i32 @abs_nabs_x12(i32 %x) {
649+
%cmp = icmp slt i32 %x, 1
650+
%sub = sub nsw i32 0, %x
651+
%cond = select i1 %cmp, i32 %x, i32 %sub
652+
%cmp1 = icmp slt i32 %cond, 0
653+
%sub9 = sub nsw i32 0, %cond
654+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
655+
ret i32 %cond18
656+
; CHECK-LABEL: @abs_nabs_x12(
657+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 1
658+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
659+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
660+
; CHECK-NEXT: ret i32 [[SEL]]
661+
}
662+
663+
define i32 @abs_nabs_x13(i32 %x) {
664+
%cmp = icmp sgt i32 %x, -1
665+
%sub = sub nsw i32 0, %x
666+
%cond = select i1 %cmp, i32 %sub, i32 %x
667+
%cmp1 = icmp slt i32 %cond, 1
668+
%sub9 = sub nsw i32 0, %cond
669+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
670+
ret i32 %cond18
671+
; CHECK-LABEL: @abs_nabs_x13(
672+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, -1
673+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
674+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
675+
; CHECK-NEXT: ret i32 [[SEL]]
676+
}
677+
678+
define i32 @abs_nabs_x14(i32 %x) {
679+
%cmp = icmp sgt i32 %x, 0
680+
%sub = sub nsw i32 0, %x
681+
%cond = select i1 %cmp, i32 %sub, i32 %x
682+
%cmp1 = icmp slt i32 %cond, 1
683+
%sub9 = sub nsw i32 0, %cond
684+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
685+
ret i32 %cond18
686+
; CHECK-LABEL: @abs_nabs_x14(
687+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, 0
688+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
689+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
690+
; CHECK-NEXT: ret i32 [[SEL]]
691+
}
692+
693+
define i32 @abs_nabs_x15(i32 %x) {
694+
%cmp = icmp slt i32 %x, 0
695+
%sub = sub nsw i32 0, %x
696+
%cond = select i1 %cmp, i32 %x, i32 %sub
697+
%cmp1 = icmp slt i32 %cond, 1
698+
%sub9 = sub nsw i32 0, %cond
699+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
700+
ret i32 %cond18
701+
; CHECK-LABEL: @abs_nabs_x15(
702+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 0
703+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
704+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
705+
; CHECK-NEXT: ret i32 [[SEL]]
706+
}
707+
708+
define i32 @abs_nabs_x16(i32 %x) {
709+
%cmp = icmp slt i32 %x, 1
710+
%sub = sub nsw i32 0, %x
711+
%cond = select i1 %cmp, i32 %x, i32 %sub
712+
%cmp1 = icmp slt i32 %cond, 1
713+
%sub9 = sub nsw i32 0, %cond
714+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
715+
ret i32 %cond18
716+
; CHECK-LABEL: @abs_nabs_x16(
717+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 1
718+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
719+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
720+
; CHECK-NEXT: ret i32 [[SEL]]
721+
}
722+
723+
define i32 @nabs_abs_x01(i32 %x) {
724+
%cmp = icmp sgt i32 %x, -1
725+
%sub = sub nsw i32 0, %x
726+
%cond = select i1 %cmp, i32 %x, i32 %sub
727+
%cmp1 = icmp sgt i32 %cond, -1
728+
%sub9 = sub nsw i32 0, %cond
729+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
730+
ret i32 %cond18
731+
; CHECK-LABEL: @nabs_abs_x01(
732+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, -1
733+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
734+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
735+
; CHECK-NEXT: ret i32 [[SEL]]
736+
}
737+
738+
define i32 @nabs_abs_x02(i32 %x) {
739+
%cmp = icmp sgt i32 %x, 0
740+
%sub = sub nsw i32 0, %x
741+
%cond = select i1 %cmp, i32 %x, i32 %sub
742+
%cmp1 = icmp sgt i32 %cond, -1
743+
%sub9 = sub nsw i32 0, %cond
744+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
745+
ret i32 %cond18
746+
; CHECK-LABEL: @nabs_abs_x02(
747+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, 0
748+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
749+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
750+
; CHECK-NEXT: ret i32 [[SEL]]
751+
}
752+
753+
define i32 @nabs_abs_x03(i32 %x) {
754+
%cmp = icmp slt i32 %x, 0
755+
%sub = sub nsw i32 0, %x
756+
%cond = select i1 %cmp, i32 %sub, i32 %x
757+
%cmp1 = icmp sgt i32 %cond, -1
758+
%sub9 = sub nsw i32 0, %cond
759+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
760+
ret i32 %cond18
761+
; CHECK-LABEL: @nabs_abs_x03(
762+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 0
763+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
764+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
765+
; CHECK-NEXT: ret i32 [[SEL]]
766+
}
767+
768+
define i32 @nabs_abs_x04(i32 %x) {
769+
%cmp = icmp slt i32 %x, 1
770+
%sub = sub nsw i32 0, %x
771+
%cond = select i1 %cmp, i32 %sub, i32 %x
772+
%cmp1 = icmp sgt i32 %cond, -1
773+
%sub9 = sub nsw i32 0, %cond
774+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
775+
ret i32 %cond18
776+
; CHECK-LABEL: @nabs_abs_x04(
777+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 1
778+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
779+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
780+
; CHECK-NEXT: ret i32 [[SEL]]
781+
}
782+
783+
define i32 @nabs_abs_x05(i32 %x) {
784+
%cmp = icmp sgt i32 %x, -1
785+
%sub = sub nsw i32 0, %x
786+
%cond = select i1 %cmp, i32 %x, i32 %sub
787+
%cmp1 = icmp sgt i32 %cond, 0
788+
%sub9 = sub nsw i32 0, %cond
789+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
790+
ret i32 %cond18
791+
; CHECK-LABEL: @nabs_abs_x05(
792+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, -1
793+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
794+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
795+
; CHECK-NEXT: ret i32 [[SEL]]
796+
}
797+
798+
define i32 @nabs_abs_x06(i32 %x) {
799+
%cmp = icmp sgt i32 %x, 0
800+
%sub = sub nsw i32 0, %x
801+
%cond = select i1 %cmp, i32 %x, i32 %sub
802+
%cmp1 = icmp sgt i32 %cond, 0
803+
%sub9 = sub nsw i32 0, %cond
804+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
805+
ret i32 %cond18
806+
; CHECK-LABEL: @nabs_abs_x06(
807+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, 0
808+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
809+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
810+
; CHECK-NEXT: ret i32 [[SEL]]
811+
}
812+
813+
define i32 @nabs_abs_x07(i32 %x) {
814+
%cmp = icmp slt i32 %x, 0
815+
%sub = sub nsw i32 0, %x
816+
%cond = select i1 %cmp, i32 %sub, i32 %x
817+
%cmp1 = icmp sgt i32 %cond, 0
818+
%sub9 = sub nsw i32 0, %cond
819+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
820+
ret i32 %cond18
821+
; CHECK-LABEL: @nabs_abs_x07(
822+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 0
823+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
824+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
825+
; CHECK-NEXT: ret i32 [[SEL]]
826+
}
827+
828+
define i32 @nabs_abs_x08(i32 %x) {
829+
%cmp = icmp slt i32 %x, 1
830+
%sub = sub nsw i32 0, %x
831+
%cond = select i1 %cmp, i32 %sub, i32 %x
832+
%cmp1 = icmp sgt i32 %cond, 0
833+
%sub9 = sub nsw i32 0, %cond
834+
%cond18 = select i1 %cmp1, i32 %sub9, i32 %cond
835+
ret i32 %cond18
836+
; CHECK-LABEL: @nabs_abs_x08(
837+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 1
838+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
839+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
840+
; CHECK-NEXT: ret i32 [[SEL]]
841+
}
842+
843+
define i32 @nabs_abs_x09(i32 %x) {
844+
%cmp = icmp sgt i32 %x, -1
845+
%sub = sub nsw i32 0, %x
846+
%cond = select i1 %cmp, i32 %x, i32 %sub
847+
%cmp1 = icmp slt i32 %cond, 0
848+
%sub16 = sub nsw i32 0, %cond
849+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
850+
ret i32 %cond18
851+
; CHECK-LABEL: @nabs_abs_x09(
852+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, -1
853+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
854+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
855+
; CHECK-NEXT: ret i32 [[SEL]]
856+
}
857+
858+
define i32 @nabs_abs_x10(i32 %x) {
859+
%cmp = icmp sgt i32 %x, 0
860+
%sub = sub nsw i32 0, %x
861+
%cond = select i1 %cmp, i32 %x, i32 %sub
862+
%cmp1 = icmp slt i32 %cond, 0
863+
%sub16 = sub nsw i32 0, %cond
864+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
865+
ret i32 %cond18
866+
; CHECK-LABEL: @nabs_abs_x10(
867+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, 0
868+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
869+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
870+
; CHECK-NEXT: ret i32 [[SEL]]
871+
}
872+
873+
define i32 @nabs_abs_x11(i32 %x) {
874+
%cmp = icmp slt i32 %x, 0
875+
%sub = sub nsw i32 0, %x
876+
%cond = select i1 %cmp, i32 %sub, i32 %x
877+
%cmp1 = icmp slt i32 %cond, 0
878+
%sub16 = sub nsw i32 0, %cond
879+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
880+
ret i32 %cond18
881+
; CHECK-LABEL: @nabs_abs_x11(
882+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 0
883+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
884+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
885+
; CHECK-NEXT: ret i32 [[SEL]]
886+
}
887+
888+
define i32 @nabs_abs_x12(i32 %x) {
889+
%cmp = icmp slt i32 %x, 1
890+
%sub = sub nsw i32 0, %x
891+
%cond = select i1 %cmp, i32 %sub, i32 %x
892+
%cmp1 = icmp slt i32 %cond, 0
893+
%sub16 = sub nsw i32 0, %cond
894+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
895+
ret i32 %cond18
896+
; CHECK-LABEL: @nabs_abs_x12(
897+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 1
898+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
899+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
900+
; CHECK-NEXT: ret i32 [[SEL]]
901+
}
902+
903+
define i32 @nabs_abs_x13(i32 %x) {
904+
%cmp = icmp sgt i32 %x, -1
905+
%sub = sub nsw i32 0, %x
906+
%cond = select i1 %cmp, i32 %x, i32 %sub
907+
%cmp1 = icmp slt i32 %cond, 1
908+
%sub16 = sub nsw i32 0, %cond
909+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
910+
ret i32 %cond18
911+
; CHECK-LABEL: @nabs_abs_x13(
912+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, -1
913+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
914+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
915+
; CHECK-NEXT: ret i32 [[SEL]]
916+
}
917+
918+
define i32 @nabs_abs_x14(i32 %x) {
919+
%cmp = icmp sgt i32 %x, 0
920+
%sub = sub nsw i32 0, %x
921+
%cond = select i1 %cmp, i32 %x, i32 %sub
922+
%cmp1 = icmp slt i32 %cond, 1
923+
%sub16 = sub nsw i32 0, %cond
924+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
925+
ret i32 %cond18
926+
; CHECK-LABEL: @nabs_abs_x14(
927+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, 0
928+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
929+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 [[NEG]], i32 %x
930+
; CHECK-NEXT: ret i32 [[SEL]]
931+
}
932+
933+
define i32 @nabs_abs_x15(i32 %x) {
934+
%cmp = icmp slt i32 %x, 0
935+
%sub = sub nsw i32 0, %x
936+
%cond = select i1 %cmp, i32 %sub, i32 %x
937+
%cmp1 = icmp slt i32 %cond, 1
938+
%sub16 = sub nsw i32 0, %cond
939+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
940+
ret i32 %cond18
941+
; CHECK-LABEL: @nabs_abs_x15(
942+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 0
943+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
944+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
945+
; CHECK-NEXT: ret i32 [[SEL]]
946+
}
947+
948+
define i32 @nabs_abs_x16(i32 %x) {
949+
%cmp = icmp slt i32 %x, 1
950+
%sub = sub nsw i32 0, %x
951+
%cond = select i1 %cmp, i32 %sub, i32 %x
952+
%cmp1 = icmp slt i32 %cond, 1
953+
%sub16 = sub nsw i32 0, %cond
954+
%cond18 = select i1 %cmp1, i32 %cond, i32 %sub16
955+
ret i32 %cond18
956+
; CHECK-LABEL: @nabs_abs_x16(
957+
; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 1
958+
; CHECK-NEXT: [[NEG:%[a-z0-9]+]] = sub nsw i32 0, %x
959+
; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 %x, i32 [[NEG]]
960+
; CHECK-NEXT: ret i32 [[SEL]]
961+
}

0 commit comments

Comments
 (0)
Please sign in to comment.