why does this happens? Right now I have to use a temporary variable to hold the index value ‘var1.x+width*h’.
It’s an annoying bug which I never take in consider while I have problem in the execution result until I exculde all other uncertainty codes by comparison with CPU codes step by step.
That isn’t a bug at all. Structure assignment is a standardized part of C, but how it is done is completely implementation specific. You code falls into “undefined behaviour” territory and should not be expected to work.
That compiler behavior breaks coalescing and is quite unexpected IMHO
I’ve seen such things happen before when any variable in the computation for in the index was declared volatile. Using a non-volatile temporary variable to hold the index helped in my case.