Last active
May 9, 2025 11:50
-
-
Save DocBohn/7e0ca7bdf241e9dffb069c0c4a6c51c7 to your computer and use it in GitHub Desktop.
Code that demonstrations elimination of redundant stores
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
void multiply_add(int *accumulator, int multiplier, int addend) { | |
*accumulator *= multiplier; | |
*accumulator += addend; | |
} |
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
// -fgcse-sm | |
multiply_add: | |
ldr w3, [x0] | |
madd w3, w3, w1, w2 | |
str w3, [x0] | |
ret |
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
# -fgcse-sm | |
multiply_add: | |
imull (%rdi), %esi | |
addl %edx, %esi | |
movl %esi, (%rdi) | |
ret |
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
void optimized_multiply_add(int *accumulator, int multiplier, int addend) { | |
int local_accumulator = *accumulator; | |
local_accumulator *= multiplier; | |
local_accumulator += addend; | |
*accumulator = local_accumulator; | |
} |
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
multiply_add: | |
ldr w3, [x0] | |
mul w1, w3, w1 | |
str w1, [x0] | |
add w1, w1, w2 | |
str w1, [x0] | |
ret |
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
multiply_add: | |
imull (%rdi), %esi | |
movl %esi, (%rdi) | |
addl %edx, %esi | |
movl %esi, (%rdi) | |
ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment