https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126784
--- Comment #1 from Hongtao Liu <liuhongt at gcc dot gnu.org> --- commit bc8c49094cdfbb8911d1bdb6fc421c6f56e6422c Author: Kyrylo Tkachov <[email protected]> Date: Wed Jul 29 21:27:05 2026 +0200 match.pd: extend the MIN/MAX narrowing through a cast to vectors The rule folding (type) minmax ((wide_type) a, (wide_type) b) to minmax (a, b) is restricted to scalars. Extension is monotone, so it commutes with the comparison and the outer truncation is exact, and the argument is lanewise, so it holds for vectors unchanged. The vector case additionally needs the narrow operation to be available, otherwise vector lowering would scalarise what used to be a single wide instruction. typedef int v2si __attribute__((vector_size (8))); typedef long v2di __attribute__((vector_size (16))); v2si h (v2si a, v2si b) { v2di x = __builtin_convertvector (a, v2di); v2di y = __builtin_convertvector (b, v2di); return __builtin_convertvector (x < y ? x : y, v2si); } It's supposed to handle only single_use for the result of min/max. But an alternative simplification is v2di x = __builtin_convertvector (a, v2di); v2di y = __builtin_convertvector (b, v2di); v2di z = x < y ? x : y; to v2si z' = a < y ? a : b; v2di z = __builtin_convertvector (b, v2di); which have 1 less builtin_convertvector, and benifits more when v2si support min/max but v2di doesn't support min/max,
