Loop expansion cannot be optimized if there is a possibility that the size difference prevents the loop control variable from expressing the data to be compared when determining whether the loop end condition is met. For example, if the loop control variable is signed char while the data to be compared is signed long, loop expansion is not optimized. Thus, compared to signed char and signed short, it is easier to perform optimization of loop expansion for signed long. To optimize loop expansion, specify the loop control variable as a 4-byte integer type.
Source code before improvement
signed long array_size=16; signed char array[16]; void func() { signed char I; for(i=0;i<array_size;i++) { array[i]=0; } } |
Assembly-language expansion code before improvement
signed long array_size=16; signed char array[16]; void func() { signed long I; for(i=0;i<array_size;i++) { array[i]=0; } } |
Assembly-language expansion code after improvement