-
Notifications
You must be signed in to change notification settings - Fork 274
Incorrect store merging causes misaligned stores #289
Comments
Thanks for report that, it seems interesting bug...that's not cause by I need more time to figure out what happen. |
A git bisect on the FSF GCC tree points the blame at commit f5e18dd
This suggests the failure occurs in 168t.fre4. Except that the wrong code doesn't appear until 299r.jump2. I get the right result if I use -fno-slp-vectorize, or if I comment out the pass_fre inside pass_pre_slp_scalar_cleanup in passes.def. Very odd. There might be some internal state that doesn't appear in the dump files that is messed up. Or maybe git bisect is accidentally pointing me at the wrong patch because of complex interactions between the various optimization patches. This needs more investigation. |
I was looking at where the block of half word stores was being optimized away which happens late, but is not where the real problem is. I failed to notice that they weren't half-word stores anymore. The problem occurs in 170t.slp1 which vectorizes the block of half-word stores. This appears to happen because 168t.fre4 optimized away a phi node. So my bisect appears to be correct. I'm not an expert on any of these passes in question, so we should file this upstream. This looks target independent, but is only a problem on targets that don't support unaligned loads/stores, and RISC-V is unfortunately the only major architecture in that category. |
I filed a bug upstream |
There is a fix on FSF GCC mainline for this now. No fix available for gcc-11 yet. |
Looks like it was cherry picked into gcc-11, can we get it into the riscv-gcc repo? |
GCC 12 will release soon, I plan bump to GCC 12 once it release, so that problem should gone :) |
Compiling this C code with commit 5964b5c (GCC 11.1.0) and the options
-march=rv64gc -O3
:yields the following (incorrect) assembly:
This causes misaligned stores when the pointer given to
zero()
is not aligned on a 4-byte boundary. I tried to use the option-fno-store-merging
as a workaround to prevent this, but the output was the same (which I suspect is yet another bug).With GCC 10.2.0, the output seems fine (again with
-march=rv64gc -O3
):The text was updated successfully, but these errors were encountered: