panfrost: fix strict aliasing violations
I've tried to fix all the strict aliasing violations the compiler was complaining about, to prevent something like #8627 (closed) from happening again.
Some of these patches add memcpy
s, which could turn into a performance regression if the compiler doesn't optimize it properly. With that in mind, I used the compiler explorer tool to make sure the generated code by gcc and clang with -O2 is equivalent to the previous code. For example, for the gen_pack
patches, the comparison can be found here:
And for the bi_apply_swizzle change, click here for the comparison.
The other patches are either less relevant performance-wise or easier to see that it shouldn't regress.
The last patch is a revert of the workaround that we implemented for the original T860 crash that led me down this path. We shouldn't need this workaround anymore.
There's just one last warning that I didn't address because I couldn't think of a clean fix for it, which is:
../src/panfrost/compiler/valhall/va_lower_constants.c: In function ‘va_lut_index_16’:
../src/panfrost/compiler/valhall/va_lower_constants.c:54:34: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
54 | uint16_t *arr16 = (uint16_t *)valhall_immediates;
| ^~~~~~~~~~~~~~~~~~