llvm.org GIT mirror llvm / 8dbc761
[InstSimplify] fold fcmp (maxnum, X, C1), C2 This is the sibling transform for rL360899 (D61691): maxnum(X, GreaterC) == C --> false maxnum(X, GreaterC) <= C --> false maxnum(X, GreaterC) < C --> false maxnum(X, GreaterC) >= C --> true maxnum(X, GreaterC) > C --> true maxnum(X, GreaterC) != C --> true git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361118 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 months ago
2 changed file(s) with 39 addition(s) and 53 deletion(s). Raw diff Collapse all Expand all
34343434 }
34353435
34363436 // Check comparison of constant with minnum with smaller constant.
3437 // TODO: Add the related transform for maxnum.
3438 const APFloat *MinC;
3439 if (match(LHS,
3440 m_Intrinsic(m_Value(), m_APFloat(MinC))) &&
3441 MinC->compare(*C) == APFloat::cmpLessThan) {
3442 // The 'less-than' relationship and minnum guarantee that we do not have
3443 // NaN constants, so ordered and unordered preds are handled the same.
3437 const APFloat *C2;
3438 if ((match(LHS, m_Intrinsic(m_Value(), m_APFloat(C2))) &&
3439 C2->compare(*C) == APFloat::cmpLessThan) ||
3440 (match(LHS, m_Intrinsic(m_Value(), m_APFloat(C2))) &&
3441 C2->compare(*C) == APFloat::cmpGreaterThan)) {
3442 bool IsMaxNum =
3443 cast(LHS)->getIntrinsicID() == Intrinsic::maxnum;
3444 // The ordered relationship and minnum/maxnum guarantee that we do not
3445 // have NaN constants, so ordered/unordered preds are handled the same.
34443446 switch (Pred) {
34453447 case FCmpInst::FCMP_OEQ: case FCmpInst::FCMP_UEQ:
3448 // minnum(X, LesserC) == C --> false
3449 // maxnum(X, GreaterC) == C --> false
3450 return getFalse(RetTy);
3451 case FCmpInst::FCMP_ONE: case FCmpInst::FCMP_UNE:
3452 // minnum(X, LesserC) != C --> true
3453 // maxnum(X, GreaterC) != C --> true
3454 return getTrue(RetTy);
34463455 case FCmpInst::FCMP_OGE: case FCmpInst::FCMP_UGE:
34473456 case FCmpInst::FCMP_OGT: case FCmpInst::FCMP_UGT:
3448 // minnum(X, LesserC) == C --> false
3449 // minnum(X, LesserC) >= C --> false
3450 // minnum(X, LesserC) > C --> false
3451 return getFalse(RetTy);
3452 case FCmpInst::FCMP_ONE: case FCmpInst::FCMP_UNE:
3457 // minnum(X, LesserC) >= C --> false
3458 // minnum(X, LesserC) > C --> false
3459 // maxnum(X, GreaterC) >= C --> true
3460 // maxnum(X, GreaterC) > C --> true
3461 return ConstantInt::get(RetTy, IsMaxNum);
34533462 case FCmpInst::FCMP_OLE: case FCmpInst::FCMP_ULE:
34543463 case FCmpInst::FCMP_OLT: case FCmpInst::FCMP_ULT:
3455 // minnum(X, LesserC) != C --> true
3456 // minnum(X, LesserC) <= C --> true
3457 // minnum(X, LesserC) < C --> true
3458 return getTrue(RetTy);
3464 // minnum(X, LesserC) <= C --> true
3465 // minnum(X, LesserC) < C --> true
3466 // maxnum(X, GreaterC) <= C --> false
3467 // maxnum(X, GreaterC) < C --> false
3468 return ConstantInt::get(RetTy, !IsMaxNum);
34593469 default:
34603470 // TRUE/FALSE/ORD/UNO should be handled before this.
34613471 llvm_unreachable("Unexpected fcmp predicate");
681681
682682 define i1 @maxnum_oeq_large_max_constant(float %x) {
683683 ; CHECK-LABEL: @maxnum_oeq_large_max_constant(
684 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.500000e+00)
685 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oeq float [[MAX]], 1.000000e+00
686 ; CHECK-NEXT: ret i1 [[CMP]]
684 ; CHECK-NEXT: ret i1 false
687685 ;
688686 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
689687 %cmp = fcmp oeq float %max, 1.0
694692
695693 define i1 @maxnum_olt_large_max_constant(float %x) {
696694 ; CHECK-LABEL: @maxnum_olt_large_max_constant(
697 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.500000e+00)
698 ; CHECK-NEXT: [[CMP:%.*]] = fcmp olt float [[MAX]], 1.000000e+00
699 ; CHECK-NEXT: ret i1 [[CMP]]
695 ; CHECK-NEXT: ret i1 false
700696 ;
701697 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
702698 %cmp = fcmp olt float %max, 1.0
707703
708704 define i1 @maxnum_ole_large_max_constant(float %x) {
709705 ; CHECK-LABEL: @maxnum_ole_large_max_constant(
710 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.500000e+00)
711 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ole float [[MAX]], 1.000000e+00
712 ; CHECK-NEXT: ret i1 [[CMP]]
706 ; CHECK-NEXT: ret i1 false
713707 ;
714708 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
715709 %cmp = fcmp ole float %max, 1.0
720714
721715 define i1 @maxnum_ueq_large_max_constant(float %x) {
722716 ; CHECK-LABEL: @maxnum_ueq_large_max_constant(
723 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.500000e+00)
724 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ueq float [[MAX]], 1.000000e+00
725 ; CHECK-NEXT: ret i1 [[CMP]]
717 ; CHECK-NEXT: ret i1 false
726718 ;
727719 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
728720 %cmp = fcmp ueq float %max, 1.0
733725
734726 define i1 @maxnum_ult_large_max_constant(float %x) {
735727 ; CHECK-LABEL: @maxnum_ult_large_max_constant(
736 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.500000e+00)
737 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ult float [[MAX]], 1.000000e+00
738 ; CHECK-NEXT: ret i1 [[CMP]]
728 ; CHECK-NEXT: ret i1 false
739729 ;
740730 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
741731 %cmp = fcmp ult float %max, 1.0
746736
747737 define <2 x i1> @maxnum_ule_large_max_constant(<2 x float> %x) {
748738 ; CHECK-LABEL: @maxnum_ule_large_max_constant(
749 ; CHECK-NEXT: [[MAX:%.*]] = call <2 x float> @llvm.maxnum.v2f32(<2 x float> [[X:%.*]], <2 x float> )
750 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ule <2 x float> [[MAX]],
751 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
739 ; CHECK-NEXT: ret <2 x i1> zeroinitializer
752740 ;
753741 %max = call <2 x float> @llvm.maxnum.v2f32(<2 x float> %x, <2 x float> )
754742 %cmp = fcmp ule <2 x float> %max,
759747
760748 define <2 x i1> @maxnum_ogt_large_max_constant(<2 x float> %x) {
761749 ; CHECK-LABEL: @maxnum_ogt_large_max_constant(
762 ; CHECK-NEXT: [[MAX:%.*]] = call <2 x float> @llvm.maxnum.v2f32(<2 x float> [[X:%.*]], <2 x float> )
763 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt <2 x float> [[MAX]],
764 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
750 ; CHECK-NEXT: ret <2 x i1>
765751 ;
766752 %max = call <2 x float> @llvm.maxnum.v2f32(<2 x float> %x, <2 x float> )
767753 %cmp = fcmp ogt <2 x float> %max,
772758
773759 define i1 @maxnum_oge_large_max_constant(float %x) {
774760 ; CHECK-LABEL: @maxnum_oge_large_max_constant(
775 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.500000e+00)
776 ; CHECK-NEXT: [[CMP:%.*]] = fcmp oge float [[MAX]], 1.000000e+00
777 ; CHECK-NEXT: ret i1 [[CMP]]
761 ; CHECK-NEXT: ret i1 true
778762 ;
779763 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
780764 %cmp = fcmp oge float %max, 1.0
785769
786770 define i1 @maxnum_one_large_max_constant(float %x) {
787771 ; CHECK-LABEL: @maxnum_one_large_max_constant(
788 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.500000e+00)
789 ; CHECK-NEXT: [[CMP:%.*]] = fcmp one float [[MAX]], 1.000000e+00
790 ; CHECK-NEXT: ret i1 [[CMP]]
772 ; CHECK-NEXT: ret i1 true
791773 ;
792774 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
793775 %cmp = fcmp one float %max, 1.0
798780
799781 define i1 @maxnum_ugt_large_max_constant(float %x) {
800782 ; CHECK-LABEL: @maxnum_ugt_large_max_constant(
801 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.500000e+00)
802 ; CHECK-NEXT: [[CMP:%.*]] = fcmp ugt float [[MAX]], 1.000000e+00
803 ; CHECK-NEXT: ret i1 [[CMP]]
783 ; CHECK-NEXT: ret i1 true
804784 ;
805785 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
806786 %cmp = fcmp ugt float %max, 1.0
811791
812792 define i1 @maxnum_uge_large_max_constant(float %x) {
813793 ; CHECK-LABEL: @maxnum_uge_large_max_constant(
814 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.500000e+00)
815 ; CHECK-NEXT: [[CMP:%.*]] = fcmp uge float [[MAX]], 1.000000e+00
816 ; CHECK-NEXT: ret i1 [[CMP]]
794 ; CHECK-NEXT: ret i1 true
817795 ;
818796 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
819797 %cmp = fcmp uge float %max, 1.0
824802
825803 define i1 @maxnum_une_large_max_constant(float %x) {
826804 ; CHECK-LABEL: @maxnum_une_large_max_constant(
827 ; CHECK-NEXT: [[MAX:%.*]] = call float @llvm.maxnum.f32(float [[X:%.*]], float 1.500000e+00)
828 ; CHECK-NEXT: [[CMP:%.*]] = fcmp une float [[MAX]], 1.000000e+00
829 ; CHECK-NEXT: ret i1 [[CMP]]
805 ; CHECK-NEXT: ret i1 true
830806 ;
831807 %max = call float @llvm.maxnum.f32(float %x, float 1.5)
832808 %cmp = fcmp une float %max, 1.0
861837 ret i1 %cmp
862838 }
863839
864 ; Partial negative test (the minnum simplifies):
840 ; Partial negative test (the maxnum simplifies):
865841 ; max(x, NaN) != 1.0 --> x != 1.0
866842
867843 define i1 @maxnum_une_nan_max_constant(float %x) {