r/Compilers • • Aug 14 '26

Optimization Question

How do compilers optimize constructs of this form ?

for(i=o; i<inputs; i++) {

A[i] = B[i];

B[i] = A[i];

}

7 Upvotes

8 comments sorted by

View all comments

Show parent comment

3

u/EggplantExtra4946 Aug 14 '26 edited Aug 14 '26

B[i] = A[i]; should be redundant but the first statement isn't.

Since memory accesses are involved, it's unclear wether the question is about simple copy propagation, redundant store elimination, maybe he think those are obvious and is asking how to ensure that they are legal using alias analysis, or since it is a loop, wether he's expecting the loop to be unrolled or vectorized.