Skip to content

Commit 201faec

Browse files
sunshaocetru
authored andcommitted
Add RV64 constraint to SRLIW (#69416)
Fixes #69408 (cherry picked from commit f48dab523784252448dbd42e72f0048ee0463368)
1 parent e957e6d commit 201faec

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -991,12 +991,12 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
991991
unsigned TrailingOnes = llvm::countr_one(Mask);
992992
if (ShAmt >= TrailingOnes)
993993
break;
994-
// If the mask has 32 trailing ones, use SRLIW.
994+
// If the mask has 32 trailing ones, use SRLI on RV32 or SRLIW on RV64.
995995
if (TrailingOnes == 32) {
996-
SDNode *SRLIW =
997-
CurDAG->getMachineNode(RISCV::SRLIW, DL, VT, N0->getOperand(0),
998-
CurDAG->getTargetConstant(ShAmt, DL, VT));
999-
ReplaceNode(Node, SRLIW);
996+
SDNode *SRLI = CurDAG->getMachineNode(
997+
Subtarget->is64Bit() ? RISCV::SRLIW : RISCV::SRLI, DL, VT,
998+
N0->getOperand(0), CurDAG->getTargetConstant(ShAmt, DL, VT));
999+
ReplaceNode(Node, SRLI);
10001000
return;
10011001
}
10021002

llvm/test/CodeGen/RISCV/aext.ll

+21
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)