Skip to content

Redundant zero-extension when converting an int16 load to an int32# #3344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dvulakh opened this issue Dec 5, 2024 · 0 comments
Open

Redundant zero-extension when converting an int16 load to an int32# #3344

dvulakh opened this issue Dec 5, 2024 · 0 comments
Labels

Comments

@dvulakh
Copy link
Contributor

dvulakh commented Dec 5, 2024

Example program:

type bigstring = (char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t

external unsafe_get_16 : bigstring -> pos:int64# -> int =  "%caml_bigstring_get16u_indexed_by_int64#"

let unsafe_get_16_as_32 t ~pos = unsafe_get_16 t ~pos |> Stdlib_upstream_compatible.Int32_u.of_int

cmm (post #3336):

 (>>s
   (<<
     (let ba_data/658 (load_mut int (+a t/655 8))
       (load_mut unsigned int16 (+ ba_data/658 pos/656)))
     32)
   32))

asm (post #3336):

movq	8(%rax), %rax
movzwq	(%rax,%rbx), %rax
movslq	%eax, %rax
ret

The movslq is a noop after the movzwq, because there is no point in sign-extending the bottom 32 bits of %rax if the bottom 16 were populated with a zero-extending load.

It is possible to write this simplification at the cmm level, though doing so requires confidence that load_mut at a small size always becomes a zero-extending load.

@dvulakh dvulakh added the backend label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant