Skip to content

Commit

Permalink
riscv64: Fix missing extensions for 8/16-bit div/rem
Browse files Browse the repository at this point in the history
This was mistakenly left out of my recent refactor for
remainder/division.

Closes bytecodealliance#7245
  • Loading branch information
alexcrichton committed Oct 17, 2023
1 parent 5481c1f commit 8bea712
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cranelift/codegen/src/isa/riscv64/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@
(rule 1 (lower (has_type (fits_in_16 ty) (sdiv x y @ (iconst imm))))
(if-let $true (has_m))
(if (safe_divisor_from_imm64 ty imm))
(rv_divw (sext x) y))
(rv_divw (sext x) (sext y)))

(rule 2 (lower (has_type $I32 (sdiv x y)))
(if-let $true (has_m))
Expand Down Expand Up @@ -604,7 +604,7 @@
(rule 1 (lower (has_type (fits_in_16 ty) (urem x y @ (iconst imm))))
(if-let $true (has_m))
(if (safe_divisor_from_imm64 ty imm))
(rv_remuw (zext x) y))
(rv_remuw (zext x) (zext y)))

(rule 2 (lower (has_type $I32 (urem x y)))
(if-let $true (has_m))
Expand Down Expand Up @@ -633,7 +633,7 @@
(rule 1 (lower (has_type (fits_in_16 ty) (srem x y @ (iconst imm))))
(if-let $true (has_m))
(if (safe_divisor_from_imm64 ty imm))
(rv_remw (sext x) y))
(rv_remw (sext x) (sext y)))

(rule 2 (lower (has_type $I32 (srem x y)))
(if-let $true (has_m))
Expand Down
10 changes: 10 additions & 0 deletions cranelift/filetests/filetests/runtests/urem.clif
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,13 @@ block0(v0: i8):
; run: %urem_imm_i8(-19) == 0
; run: %urem_imm_i8(0xC0) == 0
; run: %urem_imm_i8(0x80) == 2


function %constant_inputs() -> i8 {
block0:
v3 = iconst.i8 208
v11 = urem v3, v3 ; v3 = 208, v3 = 208
return v11
}

; run: %constant_inputs() == 0

0 comments on commit 8bea712

Please sign in to comment.