@@ -2870,6 +2870,8 @@ SDValue PPCDAGToDAGISel::get32BitZExtCompare(SDValue LHS, SDValue RHS,
2870
2870
ISD::CondCode CC,
2871
2871
int64_t RHSValue, SDLoc dl) {
2872
2872
bool IsRHSZero = RHSValue == 0 ;
2873
+ bool IsRHSOne = RHSValue == 1 ;
2874
+ bool IsRHSNegOne = RHSValue == -1LL ;
2873
2875
switch (CC) {
2874
2876
default : return SDValue ();
2875
2877
case ISD::SETEQ: {
@@ -2903,6 +2905,9 @@ SDValue PPCDAGToDAGISel::get32BitZExtCompare(SDValue LHS, SDValue RHS,
2903
2905
// (zext (setcc %a, 0, setge)) -> (lshr (~ %a), 31)
2904
2906
if (IsRHSZero)
2905
2907
return getCompoundZeroComparisonInGPR (LHS, dl, ZeroCompare::GEZExt);
2908
+
2909
+ // Not a special case (i.e. RHS == 0). Handle (%a >= %b) as (%b <= %a)
2910
+ // by swapping inputs and falling through.
2906
2911
std::swap (LHS, RHS);
2907
2912
ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS);
2908
2913
IsRHSZero = RHSConst && RHSConst->isNullValue ();
@@ -2926,6 +2931,55 @@ SDValue PPCDAGToDAGISel::get32BitZExtCompare(SDValue LHS, SDValue RHS,
2926
2931
SDValue (CurDAG->getMachineNode (PPC::XORI8, dl,
2927
2932
MVT::i64 , Shift, getI32Imm (1 , dl)), 0 );
2928
2933
}
2934
+ case ISD::SETGT: {
2935
+ // (zext (setcc %a, %b, setgt)) -> (lshr (sub %b, %a), 63)
2936
+ // (zext (setcc %a, -1, setgt)) -> (lshr (~ %a), 31)
2937
+ // (zext (setcc %a, 0, setgt)) -> (lshr (- %a), 63)
2938
+ // Handle SETLT -1 (which is equivalent to SETGE 0).
2939
+ if (IsRHSNegOne)
2940
+ return getCompoundZeroComparisonInGPR (LHS, dl, ZeroCompare::GEZExt);
2941
+
2942
+ if (IsRHSZero) {
2943
+ // The upper 32-bits of the register can't be undefined for this sequence.
2944
+ LHS = signExtendInputIfNeeded (LHS);
2945
+ RHS = signExtendInputIfNeeded (RHS);
2946
+ SDValue Neg =
2947
+ SDValue (CurDAG->getMachineNode (PPC::NEG8, dl, MVT::i64 , LHS), 0 );
2948
+ return SDValue (CurDAG->getMachineNode (PPC::RLDICL, dl, MVT::i64 ,
2949
+ Neg, getI32Imm (1 , dl), getI32Imm (63 , dl)), 0 );
2950
+ }
2951
+ // Not a special case (i.e. RHS == 0 or RHS == -1). Handle (%a > %b) as
2952
+ // (%b < %a) by swapping inputs and falling through.
2953
+ std::swap (LHS, RHS);
2954
+ ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS);
2955
+ IsRHSZero = RHSConst && RHSConst->isNullValue ();
2956
+ IsRHSOne = RHSConst && RHSConst->getSExtValue () == 1 ;
2957
+ LLVM_FALLTHROUGH;
2958
+ }
2959
+ case ISD::SETLT: {
2960
+ // (zext (setcc %a, %b, setlt)) -> (lshr (sub %a, %b), 63)
2961
+ // (zext (setcc %a, 1, setlt)) -> (xor (lshr (- %a), 63), 1)
2962
+ // (zext (setcc %a, 0, setlt)) -> (lshr %a, 31)
2963
+ // Handle SETLT 1 (which is equivalent to SETLE 0).
2964
+ if (IsRHSOne)
2965
+ return getCompoundZeroComparisonInGPR (LHS, dl, ZeroCompare::LEZExt);
2966
+
2967
+ if (IsRHSZero) {
2968
+ SDValue ShiftOps[] = { LHS, getI32Imm (1 , dl), getI32Imm (31 , dl),
2969
+ getI32Imm (31 , dl) };
2970
+ return SDValue (CurDAG->getMachineNode (PPC::RLWINM, dl, MVT::i32 ,
2971
+ ShiftOps), 0 );
2972
+ }
2973
+
2974
+ // The upper 32-bits of the register can't be undefined for this sequence.
2975
+ LHS = signExtendInputIfNeeded (LHS);
2976
+ RHS = signExtendInputIfNeeded (RHS);
2977
+ SDValue SUBFNode =
2978
+ SDValue (CurDAG->getMachineNode (PPC::SUBF8, dl, MVT::i64 , RHS, LHS), 0 );
2979
+ return SDValue (CurDAG->getMachineNode (PPC::RLDICL, dl, MVT::i64 ,
2980
+ SUBFNode, getI64Imm (1 , dl),
2981
+ getI64Imm (63 , dl)), 0 );
2982
+ }
2929
2983
}
2930
2984
}
2931
2985
@@ -2935,6 +2989,9 @@ SDValue PPCDAGToDAGISel::get32BitSExtCompare(SDValue LHS, SDValue RHS,
2935
2989
ISD::CondCode CC,
2936
2990
int64_t RHSValue, SDLoc dl) {
2937
2991
bool IsRHSZero = RHSValue == 0 ;
2992
+ bool IsRHSOne = RHSValue == 1 ;
2993
+ bool IsRHSNegOne = RHSValue == -1LL ;
2994
+
2938
2995
switch (CC) {
2939
2996
default : return SDValue ();
2940
2997
case ISD::SETEQ: {
@@ -2978,6 +3035,9 @@ SDValue PPCDAGToDAGISel::get32BitSExtCompare(SDValue LHS, SDValue RHS,
2978
3035
// (sext (setcc %a, 0, setge)) -> (ashr (~ %a), 31)
2979
3036
if (IsRHSZero)
2980
3037
return getCompoundZeroComparisonInGPR (LHS, dl, ZeroCompare::GESExt);
3038
+
3039
+ // Not a special case (i.e. RHS == 0). Handle (%a >= %b) as (%b <= %a)
3040
+ // by swapping inputs and falling through.
2981
3041
std::swap (LHS, RHS);
2982
3042
ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS);
2983
3043
IsRHSZero = RHSConst && RHSConst->isNullValue ();
@@ -3002,6 +3062,47 @@ SDValue PPCDAGToDAGISel::get32BitSExtCompare(SDValue LHS, SDValue RHS,
3002
3062
return SDValue (CurDAG->getMachineNode (PPC::ADDI8, dl, MVT::i64 , Srdi,
3003
3063
getI32Imm (-1 , dl)), 0 );
3004
3064
}
3065
+ case ISD::SETGT: {
3066
+ // (sext (setcc %a, %b, setgt)) -> (ashr (sub %b, %a), 63)
3067
+ // (sext (setcc %a, -1, setgt)) -> (ashr (~ %a), 31)
3068
+ // (sext (setcc %a, 0, setgt)) -> (ashr (- %a), 63)
3069
+ if (IsRHSNegOne)
3070
+ return getCompoundZeroComparisonInGPR (LHS, dl, ZeroCompare::GESExt);
3071
+ if (IsRHSZero) {
3072
+ // The upper 32-bits of the register can't be undefined for this sequence.
3073
+ LHS = signExtendInputIfNeeded (LHS);
3074
+ RHS = signExtendInputIfNeeded (RHS);
3075
+ SDValue Neg =
3076
+ SDValue (CurDAG->getMachineNode (PPC::NEG8, dl, MVT::i64 , LHS), 0 );
3077
+ return SDValue (CurDAG->getMachineNode (PPC::SRADI, dl, MVT::i64 , Neg,
3078
+ getI64Imm (63 , dl)), 0 );
3079
+ }
3080
+ // Not a special case (i.e. RHS == 0 or RHS == -1). Handle (%a > %b) as
3081
+ // (%b < %a) by swapping inputs and falling through.
3082
+ std::swap (LHS, RHS);
3083
+ ConstantSDNode *RHSConst = dyn_cast<ConstantSDNode>(RHS);
3084
+ IsRHSZero = RHSConst && RHSConst->isNullValue ();
3085
+ IsRHSOne = RHSConst && RHSConst->getSExtValue () == 1 ;
3086
+ LLVM_FALLTHROUGH;
3087
+ }
3088
+ case ISD::SETLT: {
3089
+ // (sext (setcc %a, %b, setgt)) -> (ashr (sub %a, %b), 63)
3090
+ // (sext (setcc %a, 1, setgt)) -> (add (lshr (- %a), 63), -1)
3091
+ // (sext (setcc %a, 0, setgt)) -> (ashr %a, 31)
3092
+ if (IsRHSOne)
3093
+ return getCompoundZeroComparisonInGPR (LHS, dl, ZeroCompare::LESExt);
3094
+ if (IsRHSZero)
3095
+ return SDValue (CurDAG->getMachineNode (PPC::SRAWI, dl, MVT::i32 , LHS,
3096
+ getI32Imm (31 , dl)), 0 );
3097
+
3098
+ // The upper 32-bits of the register can't be undefined for this sequence.
3099
+ LHS = signExtendInputIfNeeded (LHS);
3100
+ RHS = signExtendInputIfNeeded (RHS);
3101
+ SDValue SUBFNode =
3102
+ SDValue (CurDAG->getMachineNode (PPC::SUBF8, dl, MVT::i64 , RHS, LHS), 0 );
3103
+ return SDValue (CurDAG->getMachineNode (PPC::SRADI, dl, MVT::i64 ,
3104
+ SUBFNode, getI64Imm (63 , dl)), 0 );
3105
+ }
3005
3106
}
3006
3107
}
3007
3108
0 commit comments