Optimization Blocker: Memory Aliasing P394 Aliasing Two different memory references specify single location Example V:[3,2,17] combine(v, get vec start(v)+2) combine 4 (v, get vec start(v)+2)
11 Optimization Blocker: Memory Aliasing P394 • Aliasing – Two different memory references specify single location • Example – v: [3, 2, 17] – combine3(v, get_vec_start(v)+2) --> ? – combine4(v, get_vec_start(v)+2) --> ?
Optimization Blocker: Memory Aliasing Observations Easy to have happen in C Since allowed to do address arithmetic Direct access to storage structures Get in habit of introducing local variables Accumulating within loops your way of telling compiler not to check for aliasing 12
12 Optimization Blocker: Memory Aliasing • Observations – Easy to have happen in C • Since allowed to do address arithmetic • Direct access to storage structures – Get in habit of introducing local variables • Accumulating within loops • Your way of telling compiler not to check for aliasing
Optimizing Compilers Provide efficient mapping of program to machine register allocation code selection and ordering eliminating minor inefficiencies
13 Optimizing Compilers • Provide efficient mapping of program to machine – register allocation – code selection and ordering – eliminating minor inefficiencies
Optimizing Compilers Don't (usually) improve asymptotic efficiency up to programmer to select best overall algorithm big-O savings are(often)more important than constant factors but constant factors also matter Have difficulty overcoming "optimization blockers" potential memory aliasing potential procedure side-effects
14 Optimizing Compilers • Don’t (usually) improve asymptotic efficiency – up to programmer to select best overall algorithm – big-O savings are (often) more important than constant factors • but constant factors also matter • Have difficulty overcoming “optimization blockers” – potential memory aliasing – potential procedure side-effects
Limitations of Optimizing Compilers Operate Under Fundamental Constraint Must not cause any change in program behavior under al any possible condition Often prevents it from making optimizations when would only affect behavior under pathological conditions 15
15 Limitations of Optimizing Compilers • Operate Under Fundamental Constraint – Must not cause any change in program behavior under any possible condition – Often prevents it from making optimizations when would only affect behavior under pathological conditions