Skip to content

Commit

Permalink
[RISCV] Add an add.uw pattern using zext for -riscv-experimental-rv64…
Browse files Browse the repository at this point in the history
…-legal-i32 and global isel
  • Loading branch information
topperc committed Nov 11, 2023
1 parent 7e0bae5 commit 647c490
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions llvm/lib/Target/RISCV/RISCVInstrInfoZb.td
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,8 @@ def : Pat<(i32 (rotl GPR:$rs1, uimm5:$rs2)),

let Predicates = [HasStdExtZba, IsRV64] in {
def : Pat<(zext GPR:$src), (ADD_UW GPR:$src, (XLenVT X0))>;
def : Pat<(i64 (add_non_imm12 (zext GPR:$rs1), GPR:$rs2)),
(ADD_UW GPR:$rs1, GPR:$rs2)>;
}

let Predicates = [HasStdExtZbs, IsRV64] in {
Expand Down
23 changes: 23 additions & 0 deletions llvm/test/CodeGen/RISCV/GlobalISel/instruction-select/zba-rv64.mir
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,26 @@ body: |
%7:gprb(s64) = G_ANYEXT %6
$x10 = COPY %7(s64)
...
---
name: adduw
legalized: true
regBankSelected: true
tracksRegLiveness: true
body: |
bb.0.entry:
liveins: $x10, $x11
; CHECK-LABEL: name: adduw
; CHECK: liveins: $x10, $x11
; CHECK-NEXT: {{ $}}
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr = COPY $x10
; CHECK-NEXT: [[COPY1:%[0-9]+]]:gpr = COPY $x11
; CHECK-NEXT: [[ADD_UW:%[0-9]+]]:gpr = ADD_UW [[COPY]], [[COPY1]]
; CHECK-NEXT: $x10 = COPY [[ADD_UW]]
%0:gprb(s64) = COPY $x10
%1:gprb(s64) = COPY $x11
%2:gprb(s32) = G_TRUNC %0
%3:gprb(s64) = G_ZEXT %2
%4:gprb(s64) = G_ADD %3, %1
$x10 = COPY %4(s64)
...
23 changes: 23 additions & 0 deletions llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zba.ll
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,29 @@ define signext i8 @adduw_2(i32 signext %0, ptr %1) {
ret i8 %5
}

define signext i8 @adduw_3(i32 signext %0, ptr %1) {
; RV64I-LABEL: adduw_3:
; RV64I: # %bb.0:
; RV64I-NEXT: addi a0, a0, 1
; RV64I-NEXT: slli a0, a0, 32
; RV64I-NEXT: srli a0, a0, 32
; RV64I-NEXT: add a0, a1, a0
; RV64I-NEXT: lb a0, 0(a0)
; RV64I-NEXT: ret
;
; RV64ZBA-LABEL: adduw_3:
; RV64ZBA: # %bb.0:
; RV64ZBA-NEXT: addi a0, a0, 1
; RV64ZBA-NEXT: add.uw a0, a0, a1
; RV64ZBA-NEXT: lb a0, 0(a0)
; RV64ZBA-NEXT: ret
%add = add i32 %0, 1
%3 = zext i32 %add to i64
%4 = getelementptr inbounds i8, ptr %1, i64 %3
%5 = load i8, ptr %4
ret i8 %5
}

define i64 @zextw_i64(i64 %a) nounwind {
; RV64I-LABEL: zextw_i64:
; RV64I: # %bb.0:
Expand Down

0 comments on commit 647c490

Please sign in to comment.