int f(int x, int y) {
return 20 * (x - 10) + 50 * (x + 5);
}
int f_expected(int x, int y) {
return 70 * x + 50;
}
The generated code is:
f(int, int):
lea eax, [rdi-50+rdi*4]
add edi, 5
imul edi, edi, 50
lea eax, [rdi+rax*4]
ret
f_expected(int, int):
imul eax, edi, 70
add eax, 50
ret
I expect f
to be compiled to f_expected
. I tried -O3
and -Ofast
on GCC 7. Which flag am I looking for, exactly (if any)? clang and icc produce the expected code under -O3
.
For reference, clang code:
f(int, int):
imul eax, edi, 70
add eax, 50
ret
f_expected(int, int):
imul eax, edi, 70
add eax, 50
ret