@@ -3036,6 +3036,9 @@ bool RISCVDAGToDAGISel::SelectAddrRegRegScale(SDValue Addr,
30363036                                              unsigned  MaxShiftAmount,
30373037                                              SDValue &Base, SDValue &Index,
30383038                                              SDValue &Scale) {
3039+   if  (Addr.getOpcode () != ISD::ADD)
3040+     return  false ;
3041+ 
30393042  EVT VT = Addr.getSimpleValueType ();
30403043  auto  UnwrapShl = [this , VT, MaxShiftAmount](SDValue N, SDValue &Index,
30413044                                              SDValue &Shift) {
@@ -3054,29 +3057,27 @@ bool RISCVDAGToDAGISel::SelectAddrRegRegScale(SDValue Addr,
30543057    return  ShiftAmt != 0 ;
30553058  };
30563059
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 );
30783072      return  true ;
30793073    }
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 ;
30803081  }
30813082
30823083  return  false ;
0 commit comments