Skip to content

Commit f48dab5

Browse files
authored
Add RV64 constraint to SRLIW (#69416)
Fixes #69408
1 parent 51a2ac6 commit f48dab5

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,12 +1013,12 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
10131013
unsigned TrailingOnes = llvm::countr_one(Mask);
10141014
if (ShAmt >= TrailingOnes)
10151015
break;
1016-
// If the mask has 32 trailing ones, use SRLIW.
1016+
// If the mask has 32 trailing ones, use SRLI on RV32 or SRLIW on RV64.
10171017
if (TrailingOnes == 32) {
1018-
SDNode *SRLIW =
1019-
CurDAG->getMachineNode(RISCV::SRLIW, DL, VT, N0->getOperand(0),
1020-
CurDAG->getTargetConstant(ShAmt, DL, VT));
1021-
ReplaceNode(Node, SRLIW);
1018+
SDNode *SRLI = CurDAG->getMachineNode(
1019+
Subtarget->is64Bit() ? RISCV::SRLIW : RISCV::SRLI, DL, VT,
1020+
N0->getOperand(0), CurDAG->getTargetConstant(ShAmt, DL, VT));
1021+
ReplaceNode(Node, SRLI);
10221022
return;
10231023
}
10241024

llvm/test/CodeGen/RISCV/aext.ll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3+
; RUN: | FileCheck -check-prefix=RV32I %s
4+
; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5+
; RUN: | FileCheck -check-prefix=RV64I %s
6+
7+
define i24 @aext(i32 %0) {
8+
; RV32I-LABEL: aext:
9+
; RV32I: # %bb.0:
10+
; RV32I-NEXT: srli a0, a0, 8
11+
; RV32I-NEXT: ret
12+
;
13+
; RV64I-LABEL: aext:
14+
; RV64I: # %bb.0:
15+
; RV64I-NEXT: srliw a0, a0, 8
16+
; RV64I-NEXT: ret
17+
%2 = and i32 %0, -256
18+
%3 = lshr exact i32 %2, 8
19+
%4 = trunc i32 %3 to i24
20+
ret i24 %4
21+
}

0 commit comments

Comments
 (0)