https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122583
--- Comment #16 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Andrew Stubbs <[email protected]>: https://gcc.gnu.org/g:9ca1edea42f626844222ac4befa1e97675514b6c commit r17-5811-g9ca1edea42f626844222ac4befa1e97675514b6c Author: Andrew Stubbs <[email protected]> Date: Thu Oct 29 16:04:16 2026 +0000 combine, amdgcn: Fix ICE truncating wide vectors; allow packed accesses [PR122583] GCN has been disallowing misaligned vector accesses when there are packed structs in order to work around an ICE I couldn't previously explain. This of course was not ideal and caused other failures, including pr122583, indirectly. The original ICE occurred during the combine pass, when building testcase gfortran.dg/recursive_alloc_comp_4.f08, but I had assumed it was caused by something in the way the GCN port handles subregs. In general, subregs of vectors are complicated, on GCN, because vector registers cannot be treated as a single sequence of bits that can be subdivided and reinterpreted any which way, which is contrary to assumptions made in various parts of the compiler. However, I now believe this issue to be a latent bug -- or at least a new kind of edge case -- in the combine pass itself. Given (set (reg:SI 7) (subreg:SI (vec_merge:V4DI ...) 0)) force_to_mode calls "gen_lowpart_or_truncate (SImode, <V4DI>)". On GCN, truncating 256 bits to 32 bits is not a no-op, so the function tries to reinterpret the operand as an integer of the same size, using "int_mode_for_mode (V4DImode).require ()". GCN has no integer mode wider than TImode, so this fails. Unpatched trunk hits the same ICE in gcc.dg/Warray-bounds-69.c, gcc.dg/Wstringop-overflow-47.c and gfortran.fortran-torture/compile/{20080806-1,pr66251}.f90. This patch makes gen_lowpart_or_truncate return (clobber (const_int 0)) when there is no suitable integer mode, so that the combination fails cleanly, and removes the GCN workaround. With the ICE fixed, GCN now gives the expected pr97027 diagnostics in Wstringop-overflow-47.c, as aarch64 does, so add amdgcn to the xfail exceptions there. recursive_alloc_comp_4.f08 no longer reproduces the ICE on current trunk, so add an RTL testcase that starts at combine. Assisted-By: Claude Opus 5.5 Claude assisted with the analysis, and generated the testcase. gcc/ChangeLog: PR target/122583 * combine.cc (gen_lowpart_or_truncate): Return a CLOBBER if either mode has no equivalent integer mode, instead of ICEing. * config/gcn/gcn.cc (gcn_vectorize_support_vector_misalignment): Allow packed accesses. gcc/testsuite/ChangeLog: PR target/122583 * gcc.dg/Wstringop-overflow-47.c: Don't xfail pr97027 on amdgcn. * gcc.target/gcn/pr122583.c: New test.
