Repository navigation
perf(x64): optimize i8 multiplication by constants - #14796
Open
shrayjaiswal050-design wants to merge 1 commit into
Open
shrayjaiswal050-design wants to merge 1 commit into
shrayjaiswal050-design wants to merge 1 commit into
Conversation
Use 32-bit immediate imul for wrapping i8 constant multiplication on either side. Keep byte loads in registers to avoid widening memory accesses, and add codegen and execution regression coverage. Fixes bytecodealliance#14660
shrayjaiswal050-design
requested review from
alexcrichton
and removed request for
a team
October 17, 2026 17:56
| @@ -0,0 +1,82 @@ | |||
| test compile | |||
Member
There was a problem hiding this comment.
Can this use the precise-output mode to get the full golden output listed here?
Comment on lines
+1116
to
+1122
| ;; i8 multiplication can use a 32-bit immediate multiply: only the low byte of | ||
| ;; each operand affects the low byte of the result. Force the other operand into | ||
| ;; a register so that a sinkable i8 load is never widened to a 32-bit load. | ||
| (rule -8 (lower (imul $I8 x (i32_from_iconst y))) | ||
| (x64_imul_imm $I32 (put_in_gpr x) y)) | ||
| (rule -7 (lower (imul $I8 (i32_from_iconst x) y)) | ||
| (x64_imul_imm $I32 (put_in_gpr y) x)) |
Member
There was a problem hiding this comment.
Could this perhaps have rules for $I16 as well since it seems equally applicable? Also -- are you sure this doesn't need to extend the x and y arguments appropriately? I forget the rules around multiplication and bits so I'm not sure myself
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14660.
On x64, multiplying an i8 value by a constant currently uses mulb
and can load the constant from memory. This uses a 32-bit immediate
imul instead, which gives the same low-byte result.
Byte loads remain byte-sized. Added tests for both operand orders,
wrapping results, negative constants, and inputs with unused upper bits.
Tested on Windows x64: