@@ -2842,56 +2842,6 @@ static bool isWorthFoldingAdd(SDValue Add) {
2842
2842
return true ;
2843
2843
}
2844
2844
2845
- bool RISCVDAGToDAGISel::SelectAddrRegRegScale (SDValue Addr,
2846
- unsigned MaxShiftAmount,
2847
- SDValue &Base, SDValue &Index,
2848
- SDValue &Scale) {
2849
- EVT VT = Addr.getSimpleValueType ();
2850
- auto UnwrapShl = [this , VT, MaxShiftAmount](SDValue N, SDValue &Index,
2851
- SDValue &Shift) {
2852
- uint64_t ShiftAmt = 0 ;
2853
- Index = N;
2854
-
2855
- if (N.getOpcode () == ISD::SHL && isa<ConstantSDNode>(N.getOperand (1 ))) {
2856
- // Only match shifts by a value in range [0, MaxShiftAmount].
2857
- if (N.getConstantOperandVal (1 ) <= MaxShiftAmount) {
2858
- Index = N.getOperand (0 );
2859
- ShiftAmt = N.getConstantOperandVal (1 );
2860
- }
2861
- }
2862
-
2863
- Shift = CurDAG->getTargetConstant (ShiftAmt, SDLoc (N), VT);
2864
- return ShiftAmt != 0 ;
2865
- };
2866
-
2867
- if (Addr.getOpcode () == ISD::ADD) {
2868
- if (auto *C1 = dyn_cast<ConstantSDNode>(Addr.getOperand (1 ))) {
2869
- SDValue AddrB = Addr.getOperand (0 );
2870
- if (AddrB.getOpcode () == ISD::ADD &&
2871
- UnwrapShl (AddrB.getOperand (0 ), Index, Scale) &&
2872
- !isa<ConstantSDNode>(AddrB.getOperand (1 )) &&
2873
- isInt<12 >(C1->getSExtValue ())) {
2874
- // (add (add (shl A C2) B) C1) -> (add (add B C1) (shl A C2))
2875
- SDValue C1Val =
2876
- CurDAG->getTargetConstant (C1->getZExtValue (), SDLoc (Addr), VT);
2877
- Base = SDValue (CurDAG->getMachineNode (RISCV::ADDI, SDLoc (Addr), VT,
2878
- AddrB.getOperand (1 ), C1Val),
2879
- 0 );
2880
- return true ;
2881
- }
2882
- } else if (UnwrapShl (Addr.getOperand (0 ), Index, Scale)) {
2883
- Base = Addr.getOperand (1 );
2884
- return true ;
2885
- } else {
2886
- UnwrapShl (Addr.getOperand (1 ), Index, Scale);
2887
- Base = Addr.getOperand (0 );
2888
- return true ;
2889
- }
2890
- }
2891
-
2892
- return false ;
2893
- }
2894
-
2895
2845
bool RISCVDAGToDAGISel::SelectAddrRegImm (SDValue Addr, SDValue &Base,
2896
2846
SDValue &Offset) {
2897
2847
if (SelectAddrFrameIndex (Addr, Base, Offset))
@@ -2942,8 +2892,7 @@ bool RISCVDAGToDAGISel::SelectAddrRegImm(SDValue Addr, SDValue &Base,
2942
2892
// Handle ADD with large immediates.
2943
2893
if (Addr.getOpcode () == ISD::ADD && isa<ConstantSDNode>(Addr.getOperand (1 ))) {
2944
2894
int64_t CVal = cast<ConstantSDNode>(Addr.getOperand (1 ))->getSExtValue ();
2945
- assert (!(isInt<12 >(CVal) && isInt<12 >(CVal)) &&
2946
- " simm12 not already handled?" );
2895
+ assert (!isInt<12 >(CVal) && " simm12 not already handled?" );
2947
2896
2948
2897
// Handle immediates in the range [-4096,-2049] or [2048, 4094]. We can use
2949
2898
// an ADDI for part of the offset and fold the rest into the load/store.
@@ -3077,6 +3026,56 @@ bool RISCVDAGToDAGISel::SelectAddrRegImmLsb00000(SDValue Addr, SDValue &Base,
3077
3026
return true ;
3078
3027
}
3079
3028
3029
+ bool RISCVDAGToDAGISel::SelectAddrRegRegScale (SDValue Addr,
3030
+ unsigned MaxShiftAmount,
3031
+ SDValue &Base, SDValue &Index,
3032
+ SDValue &Scale) {
3033
+ EVT VT = Addr.getSimpleValueType ();
3034
+ auto UnwrapShl = [this , VT, MaxShiftAmount](SDValue N, SDValue &Index,
3035
+ SDValue &Shift) {
3036
+ uint64_t ShiftAmt = 0 ;
3037
+ Index = N;
3038
+
3039
+ if (N.getOpcode () == ISD::SHL && isa<ConstantSDNode>(N.getOperand (1 ))) {
3040
+ // Only match shifts by a value in range [0, MaxShiftAmount].
3041
+ if (N.getConstantOperandVal (1 ) <= MaxShiftAmount) {
3042
+ Index = N.getOperand (0 );
3043
+ ShiftAmt = N.getConstantOperandVal (1 );
3044
+ }
3045
+ }
3046
+
3047
+ Shift = CurDAG->getTargetConstant (ShiftAmt, SDLoc (N), VT);
3048
+ return ShiftAmt != 0 ;
3049
+ };
3050
+
3051
+ if (Addr.getOpcode () == ISD::ADD) {
3052
+ if (auto *C1 = dyn_cast<ConstantSDNode>(Addr.getOperand (1 ))) {
3053
+ SDValue AddrB = Addr.getOperand (0 );
3054
+ if (AddrB.getOpcode () == ISD::ADD &&
3055
+ UnwrapShl (AddrB.getOperand (0 ), Index, Scale) &&
3056
+ !isa<ConstantSDNode>(AddrB.getOperand (1 )) &&
3057
+ isInt<12 >(C1->getSExtValue ())) {
3058
+ // (add (add (shl A C2) B) C1) -> (add (add B C1) (shl A C2))
3059
+ SDValue C1Val =
3060
+ CurDAG->getTargetConstant (C1->getZExtValue (), SDLoc (Addr), VT);
3061
+ Base = SDValue (CurDAG->getMachineNode (RISCV::ADDI, SDLoc (Addr), VT,
3062
+ AddrB.getOperand (1 ), C1Val),
3063
+ 0 );
3064
+ return true ;
3065
+ }
3066
+ } else if (UnwrapShl (Addr.getOperand (0 ), Index, Scale)) {
3067
+ Base = Addr.getOperand (1 );
3068
+ return true ;
3069
+ } else {
3070
+ UnwrapShl (Addr.getOperand (1 ), Index, Scale);
3071
+ Base = Addr.getOperand (0 );
3072
+ return true ;
3073
+ }
3074
+ }
3075
+
3076
+ return false ;
3077
+ }
3078
+
3080
3079
bool RISCVDAGToDAGISel::SelectAddrRegReg (SDValue Addr, SDValue &Base,
3081
3080
SDValue &Offset) {
3082
3081
if (Addr.getOpcode () != ISD::ADD)
0 commit comments