https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127100
--- Comment #13 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:1dc229c7368d4f8b43356968f624e0d895961868 commit r17-3709-g1dc229c7368d4f8b43356968f624e0d895961868 Author: Jakub Jelinek <[email protected]> Date: Thu Aug 27 20:22:55 2026 +0200 gimple-fold: Fix up len_load/len_store folding [PR127100] There are various optabs and corresponding internal functions which take 2 separate arguments, length (counted in number of vector elements) and bias. The bias is documented to be only 0 or -1 and is a property of the target. Out of rs6000, s390 and riscv backends which use any of these optabs/ifns, only s390 has bias -1 (and only defines len_load/len_store optabs), the other targets have bias 0. Now, before r14-1932 it has been documented that the optabs load/store len - bias elements, on most targets that just means len elements, except on s390 z13+ it actually loads the provided operand + 1 elements. There is one spot in sccvn which correctly uses pd.size = (tree_to_uhwi (len) + -tree_to_shwi (bias)) * BITS_PER_UNIT; r14-1932 changed the documentation to use len + bias instead for unclear reassons, but otherwise didn't change the bias handling at all. And then r16-5984 probably followed the adjusted documentation and uses wlen = wi::to_poly_widest (len) + wi::to_widest (bias); That is wrong. On the intrinsic_intkinds_1.f90 testcase, we have several .LEN_LOAD calls which have 1, -1 as the last two arguments and it actually means it loads 2 bytes, but partial_load_store_mask_state instead computes 1 + -1 = 0 and assumes it is all inactive and folds it away. The following patch adjusts the documentation in all places where bias is used I could find (admittedly, most of the optabs are only defined on riscv right now and the bias is 0 there, so it doesn't make a difference), fixes some pastos in operand numbers and finally fixes up the r16-5984 change to compute len - bias instead. 2026-08-27 Jakub Jelinek <[email protected]> PR tree-optimization/127100 * doc/md.texi (vec_mask_len_load_lanes@var{m}@var{n}): Use operand4 - operand5 rather than operand4 + operand5. (vec_mask_len_store_lanes@var{m}@var{n}): Use operand3 - operand4 rather than operand3 + operand4. (mask_len_gather_load@var{m}@var{n}): Use operand 7 - operand 8 rather than operand 7 + operand 8. (mask_len_strided_load@var{m}): Use operand 4 - operand 5 rather than operand 4 + operand 5. (mask_len_scatter_store@var{m}@var{n}): Use operand 6 - operand 7 rather than operand 6 + operand 7. (mask_len_strided_store@var{m}): Use operand 4 - operand 5 rather than operand 4 + operand 5. (len_load_@var{m}): Use operand 3 - operand 4 rather than operand 3 + operand 4. (len_store_@var{m}): Use operand 2 - operand 3 rather than operand 2 + operand 3. (mask_len_load@var{m}@var{n}): Use operand 4 - operand 5 rather than operand 3 + operand 4 or operand 4 + operand 5. Use Operand 5 rather than Operand 4 when talking about bias QI mode. (mask_len_store@var{m}@var{n}): Use operand 3 - operand 4 rather than operand 3 + operand 4 or operand 2 + operand 4. (cond_len_neg@var{mode}): Use operand 4 - operand 5 rather than operand 4 + operand 5. Use ops[4] - ops[5] rather than ops[4] + ops[5]. (cond_len_add@var{mode}): Use operand 5 - operand 6 rather than operand 5 + operand 6. Use ops[5] - ops[6] rather than ops[5] + ops[6]. (cond_len_fma@var{mode}): Use ops[6] - ops[7] rather than ops[6] + ops[7]. * gimple-fold.cc (partial_load_store_mask_state): Compute wlen as wi::to_poly_widest (len) - wi::to_widest (bias) rather than wi::to_poly_widest (len) + wi::to_widest (bias). * gfortran.dg/pr127100.f90: New test. Reviewed-by: Richard Biener <[email protected]>
