The follwing example contains functional identicaal code: <1> uses direct register access <2> uses structure mappingBut <1> suppresses the hoist/sink of the loads/stores to variable g out of the loop. In case <2> this optimization is done (and is correct).
What does avr-gcc hinder to do this optimization in case <1>? #include <avr/io.h> #include <stdint.h> static uint16_t g; int main() { for(uint8_t i = 0; i < 20; i++) { ++g; // VPORTA_DIR; // <1> suppresses optimization VPORTA.DIR; // <2> } }