Skip to content

Commit 4491382

Browse files
authored
cranelift: fix register for srem.i8 on x86_64 (#5540)
* Change register written to in specific srem case. Add regression test as filetest case. Fixes #5470 * Add another test case, newline * Update comment
1 parent e65a2c9 commit 4491382

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

cranelift/codegen/src/isa/x64/inst/emit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,10 @@ pub(crate) fn emit(
543543

544544
// Here, divisor == -1.
545545
if !kind.is_div() {
546-
// x % -1 = 0; put the result into the destination, $rdx.
546+
// x % -1 = 0; put the result into the destination, $rax.
547547
let done_label = sink.get_label();
548548

549-
let inst = Inst::imm(OperandSize::Size64, 0, Writable::from_reg(regs::rdx()));
549+
let inst = Inst::imm(OperandSize::Size64, 0, Writable::from_reg(regs::rax()));
550550
inst.emit(&[], sink, info, state);
551551

552552
let inst = Inst::jmp_known(done_label);

cranelift/filetests/filetests/runtests/srem.clif

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,12 @@ block0(v0: i8):
142142
; run: %srem_imm_i8(-19) == -1
143143
; run: %srem_imm_i8(0xC0) == -1
144144
; run: %srem_imm_i8(0x80) == -2
145+
146+
function %srem_with_bmask(i64, i8) -> i8 {
147+
block0(v0: i64, v1: i8):
148+
v2 = bmask.i8 v0
149+
v3 = srem v2, v1
150+
return v3
151+
}
152+
; run: %srem_with_bmask(4352, -1) == 0
153+
; run: %srem_with_bmask(4352, 1) == 0

0 commit comments

Comments
 (0)