https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128080
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Igor Shevlyakov <[email protected]>: https://gcc.gnu.org/g:f4c8d2716469a587a97f8a325d032d539f00e2f0 commit r17-5542-gf4c8d2716469a587a97f8a325d032d539f00e2f0 Author: Igor Shevlyakov <[email protected]> Date: Wed Oct 21 15:52:39 2026 -0700 match.pd: Use ssizetype masks when merging VEC_PERMs [PR128080] The patterns merging two VEC_PERM_EXPRs give the new selector the element type of the outer permute's mask. The new selector indexes two vectors of N elements, so its elements range over 0 .. 2N-1, and with 256 or more byte elements an 8-bit mask element cannot hold them: build_int_cst truncates the index and the merged permute reads the wrong input. For example c = VEC_PERM_EXPR <b, b, { 255, 254, ..., 0 }>; d = VEC_PERM_EXPR <x, c, { 0, -1, ... }>; was merged to VEC_PERM_EXPR <x, x, { 0, 0, ... }>, the index 256 of b[0] having become 0. A constant permute mask is not tied to the element type of the vectors it permutes, so build the new one with ssizetype elements, as the vectorizer and forwprop do, in all three patterns. Assisted-by: Claude Opus 5.5 PR tree-optimization/128080 gcc/ChangeLog: * match.pd (vec_perm (vec_perm) merges): Give the new mask ssizetype elements. gcc/testsuite/ChangeLog: * gcc.dg/torture/pr128080.c: New test. * gcc.dg/torture/pr128080-2.c: New test. Signed-off-by: Igor Shevlyakov <[email protected]>
