Skip to content

Commit b4339dd

Browse files
committed
[RISCV] Promote s32 G_SEXT_INREG for RV64
1 parent d1e17a3 commit b4339dd

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,15 @@ RISCVLegalizerInfo::RISCVLegalizerInfo(const RISCVSubtarget &ST)
159159
typeIsLegalIntOrFPVec(1, IntOrFPVecTys, ST)));
160160
if (ST.is64Bit()) {
161161
ExtActions.legalFor({{sXLen, s32}});
162-
getActionDefinitionsBuilder(G_SEXT_INREG)
163-
.customFor({s32, sXLen})
164-
.maxScalar(0, sXLen)
165-
.lower();
166-
} else {
167-
getActionDefinitionsBuilder(G_SEXT_INREG)
168-
.customFor({s32})
169-
.maxScalar(0, sXLen)
170-
.lower();
171162
}
172163
ExtActions.customIf(typeIsLegalBoolVec(1, BoolVecTys, ST))
173164
.maxScalar(0, sXLen);
174165

166+
getActionDefinitionsBuilder(G_SEXT_INREG)
167+
.customFor({sXLen})
168+
.clampScalar(0, sXLen, sXLen)
169+
.lower();
170+
175171
// Merge/Unmerge
176172
for (unsigned Op : {G_MERGE_VALUES, G_UNMERGE_VALUES}) {
177173
auto &MergeUnmergeActions = getActionDefinitionsBuilder(Op);

llvm/lib/Target/RISCV/RISCVGISel.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,6 @@ def : Pat<(shl (zext GPR:$rs), uimm5:$shamt),
218218
// Zb* RV64 i32 patterns not used by SelectionDAG.
219219
//===----------------------------------------------------------------------===//
220220

221-
let Predicates = [HasStdExtZbb, IsRV64] in {
222-
def : Pat<(i32 (sext_inreg GPR:$rs1, i8)), (SEXT_B GPR:$rs1)>;
223-
def : Pat<(i32 (sext_inreg GPR:$rs1, i16)), (SEXT_H GPR:$rs1)>;
224-
} // Predicates = [HasStdExtZbb, IsRV64]
225-
226221
let Predicates = [HasStdExtZba, IsRV64] in {
227222
def : Pat<(shl (i64 (zext GPR:$rs1)), uimm5:$shamt),
228223
(SLLI_UW GPR:$rs1, uimm5:$shamt)>;

llvm/test/CodeGen/RISCV/GlobalISel/rv64zbb.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,8 @@ define i64 @ctpop_i64(i64 %a) nounwind {
869869
define signext i32 @sextb_i32(i32 signext %a) nounwind {
870870
; RV64I-LABEL: sextb_i32:
871871
; RV64I: # %bb.0:
872-
; RV64I-NEXT: slli a0, a0, 24
873-
; RV64I-NEXT: sraiw a0, a0, 24
872+
; RV64I-NEXT: slli a0, a0, 56
873+
; RV64I-NEXT: srai a0, a0, 56
874874
; RV64I-NEXT: ret
875875
;
876876
; RV64ZBB-LABEL: sextb_i32:
@@ -901,8 +901,8 @@ define i64 @sextb_i64(i64 %a) nounwind {
901901
define signext i32 @sexth_i32(i32 signext %a) nounwind {
902902
; RV64I-LABEL: sexth_i32:
903903
; RV64I: # %bb.0:
904-
; RV64I-NEXT: slli a0, a0, 16
905-
; RV64I-NEXT: sraiw a0, a0, 16
904+
; RV64I-NEXT: slli a0, a0, 48
905+
; RV64I-NEXT: srai a0, a0, 48
906906
; RV64I-NEXT: ret
907907
;
908908
; RV64ZBB-LABEL: sexth_i32:

0 commit comments

Comments
 (0)