Skip to content

Commit 51c82b8

Browse files
authored
Winch: avoid emitting 32->64 extend on rmw ops on x64 (bytecodealliance#10037)
* avoid emitting 32->64 extend on rmw ops on x64 * review edit
1 parent e7f43b8 commit 51c82b8

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

tests/disas/winch/x64/atomic/rmw/i64_atomic_rmw32_subu.wat

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
;; movq 0x10(%r11), %r11
1313
;; addq $0x10, %r11
1414
;; cmpq %rsp, %r11
15-
;; ja 0x61
15+
;; ja 0x5f
1616
;; 1c: movq %rdi, %r14
1717
;; subq $0x10, %rsp
1818
;; movq %rdi, 8(%rsp)
@@ -21,16 +21,15 @@
2121
;; movl $0, %ecx
2222
;; andl $3, %ecx
2323
;; cmpl $0, %ecx
24-
;; jne 0x63
24+
;; jne 0x61
2525
;; 44: movl $0, %ecx
2626
;; movq 0x58(%r14), %r11
2727
;; movq (%r11), %rdx
2828
;; addq %rcx, %rdx
2929
;; negl %eax
3030
;; lock xaddl %eax, (%rdx)
31-
;; movl %eax, %eax
3231
;; addq $0x10, %rsp
3332
;; popq %rbp
3433
;; retq
34+
;; 5f: ud2
3535
;; 61: ud2
36-
;; 63: ud2

winch/codegen/src/isa/x64/masm.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,12 @@ impl Masm for MacroAssembler {
14131413
}
14141414

14151415
if let Some(extend) = extend {
1416-
self.asm.movzx_rr(operand.to_reg(), operand, extend);
1416+
// We don't need to zero-extend from 32 to 64bits.
1417+
if !(extend.from_bits() == 32 && extend.to_bits() == 64) {
1418+
self.asm.movzx_rr(operand.to_reg(), operand, extend);
1419+
}
14171420
}
1421+
14181422
Ok(())
14191423
}
14201424
}

0 commit comments

Comments
 (0)