@@ -3036,6 +3036,9 @@ bool RISCVDAGToDAGISel::SelectAddrRegRegScale(SDValue Addr,
3036
3036
unsigned MaxShiftAmount,
3037
3037
SDValue &Base, SDValue &Index,
3038
3038
SDValue &Scale) {
3039
+ if (Addr.getOpcode () != ISD::ADD)
3040
+ return false ;
3041
+
3039
3042
EVT VT = Addr.getSimpleValueType ();
3040
3043
auto UnwrapShl = [this , VT, MaxShiftAmount](SDValue N, SDValue &Index,
3041
3044
SDValue &Shift) {
@@ -3054,29 +3057,27 @@ bool RISCVDAGToDAGISel::SelectAddrRegRegScale(SDValue Addr,
3054
3057
return ShiftAmt != 0 ;
3055
3058
};
3056
3059
3057
- if (Addr.getOpcode () == ISD::ADD) {
3058
- if (auto *C1 = dyn_cast<ConstantSDNode>(Addr.getOperand (1 ))) {
3059
- SDValue AddrB = Addr.getOperand (0 );
3060
- if (AddrB.getOpcode () == ISD::ADD &&
3061
- UnwrapShl (AddrB.getOperand (0 ), Index, Scale) &&
3062
- !isa<ConstantSDNode>(AddrB.getOperand (1 )) &&
3063
- isInt<12 >(C1->getSExtValue ())) {
3064
- // (add (add (shl A C2) B) C1) -> (add (add B C1) (shl A C2))
3065
- SDValue C1Val =
3066
- CurDAG->getTargetConstant (C1->getZExtValue (), SDLoc (Addr), VT);
3067
- Base = SDValue (CurDAG->getMachineNode (RISCV::ADDI, SDLoc (Addr), VT,
3068
- AddrB.getOperand (1 ), C1Val),
3069
- 0 );
3070
- return true ;
3071
- }
3072
- } else if (UnwrapShl (Addr.getOperand (0 ), Index, Scale)) {
3073
- Base = Addr.getOperand (1 );
3074
- return true ;
3075
- } else {
3076
- UnwrapShl (Addr.getOperand (1 ), Index, Scale);
3077
- Base = Addr.getOperand (0 );
3060
+ if (auto *C1 = dyn_cast<ConstantSDNode>(Addr.getOperand (1 ))) {
3061
+ SDValue AddrB = Addr.getOperand (0 );
3062
+ if (AddrB.getOpcode () == ISD::ADD &&
3063
+ UnwrapShl (AddrB.getOperand (0 ), Index, Scale) &&
3064
+ !isa<ConstantSDNode>(AddrB.getOperand (1 )) &&
3065
+ isInt<12 >(C1->getSExtValue ())) {
3066
+ // (add (add (shl A C2) B) C1) -> (add (add B C1) (shl A C2))
3067
+ SDValue C1Val =
3068
+ CurDAG->getTargetConstant (C1->getZExtValue (), SDLoc (Addr), VT);
3069
+ Base = SDValue (CurDAG->getMachineNode (RISCV::ADDI, SDLoc (Addr), VT,
3070
+ AddrB.getOperand (1 ), C1Val),
3071
+ 0 );
3078
3072
return true ;
3079
3073
}
3074
+ } else if (UnwrapShl (Addr.getOperand (0 ), Index, Scale)) {
3075
+ Base = Addr.getOperand (1 );
3076
+ return true ;
3077
+ } else {
3078
+ UnwrapShl (Addr.getOperand (1 ), Index, Scale);
3079
+ Base = Addr.getOperand (0 );
3080
+ return true ;
3080
3081
}
3081
3082
3082
3083
return false ;
0 commit comments