Skip to content

Commit ff0cbec

Browse files
committed
[RISCV] Add a non-template version of SelectAddrRegZextRegScale and move code there. NFC
The template versions now call the non-template version. This avoids duplicating the code for each template.
1 parent 39c8cfb commit ff0cbec

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,6 +3106,25 @@ bool RISCVDAGToDAGISel::SelectAddrRegRegScale(SDValue Addr,
31063106
return true;
31073107
}
31083108

3109+
bool RISCVDAGToDAGISel::SelectAddrRegZextRegScale(SDValue Addr,
3110+
unsigned MaxShiftAmount,
3111+
unsigned Bits, SDValue &Base,
3112+
SDValue &Index,
3113+
SDValue &Scale) {
3114+
if (!SelectAddrRegRegScale(Addr, MaxShiftAmount, Base, Index, Scale))
3115+
return false;
3116+
3117+
if (Index.getOpcode() == ISD::AND) {
3118+
auto *C = dyn_cast<ConstantSDNode>(Index.getOperand(1));
3119+
if (C && C->getZExtValue() == maskTrailingOnes<uint64_t>(Bits)) {
3120+
Index = Index.getOperand(0);
3121+
return true;
3122+
}
3123+
}
3124+
3125+
return false;
3126+
}
3127+
31093128
bool RISCVDAGToDAGISel::SelectAddrRegReg(SDValue Addr, SDValue &Base,
31103129
SDValue &Offset) {
31113130
if (Addr.getOpcode() != ISD::ADD)

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,14 @@ class RISCVDAGToDAGISel : public SelectionDAGISel {
5959
return SelectAddrRegRegScale(Addr, MaxShift, Base, Index, Scale);
6060
}
6161

62+
bool SelectAddrRegZextRegScale(SDValue Addr, unsigned MaxShiftAmount,
63+
unsigned Bits, SDValue &Base, SDValue &Index,
64+
SDValue &Scale);
65+
6266
template <unsigned MaxShift, unsigned Bits>
6367
bool SelectAddrRegZextRegScale(SDValue Addr, SDValue &Base, SDValue &Index,
6468
SDValue &Scale) {
65-
if (SelectAddrRegRegScale(Addr, MaxShift, Base, Index, Scale)) {
66-
if (Index.getOpcode() == ISD::AND) {
67-
auto *C = dyn_cast<ConstantSDNode>(Index.getOperand(1));
68-
if (C && C->getZExtValue() == maskTrailingOnes<uint64_t>(Bits)) {
69-
Index = Index.getOperand(0);
70-
return true;
71-
}
72-
}
73-
}
74-
return false;
69+
return SelectAddrRegZextRegScale(Addr, MaxShift, Bits, Base, Index, Scale);
7570
}
7671

7772
bool SelectAddrRegReg(SDValue Addr, SDValue &Base, SDValue &Offset);

0 commit comments

Comments
 (0)