From: Robin Dapp Date: Fri, 7 Nov 2025 09:21:36 +0000 (+0100) Subject: optabs: Do not pun modes smaller than QImode. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a17e06fa2ab5776de129d35418e05039bd9a51b1;p=thirdparty%2Fgcc.git optabs: Do not pun modes smaller than QImode. In can_vec_perm_const_p if we cannot directly permute a vector mode we try to pun it with a byte mode. qimode_for_vec_perm checks gets the mode size and uses that as number of elements for the new QImode vector. This doesn't work for RVV mask vectors, though. First, their precision might be smaller than a byte and second, there is no way to easily pun them. The most common way would be a vector select from {0, 0, ...} and {1, 1, ...} vectors. Therefore this patch checks if the perm's innermode precision is a multiple of QImode's precision. Bootstrapped and regtested on x86 and power10. Regtested on aarch64 and riscv64. gcc/ChangeLog: * optabs-query.cc (qimode_for_vec_perm): Check if QImode's precision divides the inner mode's precision. --- diff --git a/gcc/optabs-query.cc b/gcc/optabs-query.cc index 5335d0d8401..484d7c2e205 100644 --- a/gcc/optabs-query.cc +++ b/gcc/optabs-query.cc @@ -358,7 +358,9 @@ can_conditionally_move_p (machine_mode mode) opt_machine_mode qimode_for_vec_perm (machine_mode mode) { - if (GET_MODE_INNER (mode) != QImode) + if (GET_MODE_INNER (mode) != QImode + && multiple_p (GET_MODE_PRECISION (GET_MODE_INNER (mode)), + GET_MODE_PRECISION (QImode))) return related_vector_mode (mode, QImode, GET_MODE_SIZE (mode)); return opt_machine_mode (); }