@@ -663,6 +663,20 @@ bool RISCVDAGToDAGISel::trySignedBitfieldExtract(SDNode *Node) {
663
663
return false ;
664
664
}
665
665
666
+ bool RISCVDAGToDAGISel::tryUnsignedBitfieldExtract (SDNode *Node, SDLoc DL,
667
+ MVT VT, SDValue X,
668
+ unsigned Msb, unsigned Lsb) {
669
+ // Only supported with XTHeadBb at the moment.
670
+ if (!Subtarget->hasVendorXTHeadBb ())
671
+ return false ;
672
+
673
+ SDNode *TH_EXTU = CurDAG->getMachineNode (
674
+ RISCV::TH_EXTU, DL, VT, X, CurDAG->getTargetConstant (Msb, DL, VT),
675
+ CurDAG->getTargetConstant (Lsb, DL, VT));
676
+ ReplaceNode (Node, TH_EXTU);
677
+ return true ;
678
+ }
679
+
666
680
bool RISCVDAGToDAGISel::tryIndexedLoad (SDNode *Node) {
667
681
// Target does not support indexed loads.
668
682
if (!Subtarget->hasVendorXTHeadMemIdx ())
@@ -1122,16 +1136,12 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
1122
1136
return ;
1123
1137
}
1124
1138
1125
- unsigned LShAmt = Subtarget->getXLen () - TrailingOnes;
1126
- if (Subtarget->hasVendorXTHeadBb ()) {
1127
- SDNode *THEXTU = CurDAG->getMachineNode (
1128
- RISCV::TH_EXTU, DL, VT, N0->getOperand (0 ),
1129
- CurDAG->getTargetConstant (TrailingOnes - 1 , DL, VT),
1130
- CurDAG->getTargetConstant (ShAmt, DL, VT));
1131
- ReplaceNode (Node, THEXTU);
1139
+ const unsigned Msb = TrailingOnes - 1 ;
1140
+ const unsigned Lsb = ShAmt;
1141
+ if (tryUnsignedBitfieldExtract (Node, DL, VT, N0->getOperand (0 ), Msb, Lsb))
1132
1142
return ;
1133
- }
1134
1143
1144
+ unsigned LShAmt = Subtarget->getXLen () - TrailingOnes;
1135
1145
SDNode *SLLI =
1136
1146
CurDAG->getMachineNode (RISCV::SLLI, DL, VT, N0->getOperand (0 ),
1137
1147
CurDAG->getTargetConstant (LShAmt, DL, VT));
@@ -1188,19 +1198,6 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
1188
1198
1189
1199
SDValue N0 = Node->getOperand (0 );
1190
1200
1191
- auto tryUnsignedBitfieldExtract = [&](SDNode *Node, SDLoc DL, MVT VT,
1192
- SDValue X, unsigned Msb,
1193
- unsigned Lsb) {
1194
- if (!Subtarget->hasVendorXTHeadBb ())
1195
- return false ;
1196
-
1197
- SDNode *TH_EXTU = CurDAG->getMachineNode (
1198
- RISCV::TH_EXTU, DL, VT, X, CurDAG->getTargetConstant (Msb, DL, VT),
1199
- CurDAG->getTargetConstant (Lsb, DL, VT));
1200
- ReplaceNode (Node, TH_EXTU);
1201
- return true ;
1202
- };
1203
-
1204
1201
bool LeftShift = N0.getOpcode () == ISD::SHL;
1205
1202
if (LeftShift || N0.getOpcode () == ISD::SRL) {
1206
1203
auto *C = dyn_cast<ConstantSDNode>(N0.getOperand (1 ));
0 commit comments