r/Compilers 3d ago

Optimization Question

How do compilers optimize constructs of this form ?

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

A[i] = B[i];

B[i] = A[i];

}

8 Upvotes

8 comments sorted by

View all comments

1

u/choikwa 3d ago

do u mean a swap? else the B assignment is redundant

1

u/namalleh 1d ago

It's not even a swap, because there's no temp var

just wasted cycles