Skip to content

Commit 9ba45c5

Browse files
committed
[RISCV] Move RISCVDAGToDAGISel::SelectAddrRegRegScale definition later. NFC
This function was placed between some static functions and their callers. Reorder to keep the related code together.
1 parent 3faaa5c commit 9ba45c5

File tree

1 file changed

+51
-52
lines changed

1 file changed

+51
-52
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2842,56 +2842,6 @@ static bool isWorthFoldingAdd(SDValue Add) {
28422842
return true;
28432843
}
28442844

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-
28952845
bool RISCVDAGToDAGISel::SelectAddrRegImm(SDValue Addr, SDValue &Base,
28962846
SDValue &Offset) {
28972847
if (SelectAddrFrameIndex(Addr, Base, Offset))
@@ -2942,8 +2892,7 @@ bool RISCVDAGToDAGISel::SelectAddrRegImm(SDValue Addr, SDValue &Base,
29422892
// Handle ADD with large immediates.
29432893
if (Addr.getOpcode() == ISD::ADD && isa<ConstantSDNode>(Addr.getOperand(1))) {
29442894
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?");
29472896

29482897
// Handle immediates in the range [-4096,-2049] or [2048, 4094]. We can use
29492898
// 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,
30773026
return true;
30783027
}
30793028

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+
30803079
bool RISCVDAGToDAGISel::SelectAddrRegReg(SDValue Addr, SDValue &Base,
30813080
SDValue &Offset) {
30823081
if (Addr.getOpcode() != ISD::ADD)

0 commit comments

Comments
 (0)