Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created June 4, 2019 02:51
Show Gist options
  • Save kaityo256/d5b5f3e7c309ced9a0705d6819f8a59b to your computer and use it in GitHub Desktop.
Save kaityo256/d5b5f3e7c309ced9a0705d6819f8a59b to your computer and use it in GitHub Desktop.
Constant folding with array (local variable)
#include <cstdio>
int func(int b[4]) {
int a[] = {1, 2, 3, 4};
int sum = 0;
for (int i = 0; i < 4; i++) {
sum += a[i] * b[i];
}
return sum;
}
int main() {
int b[] = {5, 6, 7, 8};
printf("%d\n", func(b));
}
@kaityo256
Copy link
Author

$ g++ -O3 -S array3.cpp
_main:
LFB2:
  subq  $8, %rsp
LCFI0:
  movl  $70, %esi
  xorl  %eax, %eax
  leaq  lC1(%rip), %rdi
  call  _printf
  xorl  %eax, %eax
  addq  $8, %rsp
LCFI1:
  ret

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment