Question: Consider the following procedure written in C: void scale _ by _ 7 ( int arr [ ] ) { int i; for ( i

Consider the following procedure written in C:
void scale_by_7(int arr[]){
int i;
for(i =0; i <100; i++)
arr[i]*=7;
}
This code has been compiled with -O2 to get the following x86 code:
xorl %eax, %eax
.L3:
movl (%rdi,%rax),%ecx
leal 0(,%rcx,8),%edx #3rd
subl %ecx, %edx #4th
movl %edx, (%rdi,%rax)
addq $4,%rax
cmpq $400,%rax
jne .L3
ret
What optimization has the compiler performed with the third and fourth assembly instructions?
code motion
strength reduction
common subexpression elimination

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!