On Fri, 4 Oct 2024, Jennifer Schmitz wrote: > As in https://gcc.gnu.org/pipermail/gcc-patches/2024-September/663185.html, > this patch guards the simplification x / y * y == x -> x % y == 0 in > match.pd for vector types by a check for: > 1) Support of the mod optab for vectors OR > 2) Application before vector lowering for non-VL vectors. > > The patch was bootstrapped and tested with no regression on > aarch64-linux-gnu and x86_64-linux-gnu. > OK for mainline?
- (if (TREE_CODE (TREE_TYPE (@0)) != COMPLEX_TYPE) + (if (TREE_CODE (TREE_TYPE (@0)) != COMPLEX_TYPE + || (VECTOR_INTEGER_TYPE_P (type) + && ((optimize_vectors_before_lowering_p () + && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST) + || target_supports_op_p (type, TRUNC_MOD_EXPR, + optab_vector)))) this looks a bit odd, VECTOR_INTEGER_TYPE_P (type) checks the result type of the comparison. I think the whole condition is better written as (if (TREE_CODE (TREE_TYPE (@0)) != COMPLEX_TYPE && (!VECTOR_MODE_P (TYPE_MODE (TREE_TYPE (@0))) || !target_supports_op_p (TREE_TYPE (@0), TRUNC_DIV_EXPR, optab_vector) || target_supports_op_p (TREE_TYPE (@0), TRUNC_MOD_EXPR, optab_vector))) when we have non-vector mode we're before lowering, likewise when the target doesn't support the division. Even before lowering we shouldn't replace a supported division (and multiplication) with an unsupported modulo. Richard. > Signed-off-by: Jennifer Schmitz <jschm...@nvidia.com> > > gcc/ > PR tree-optimization/116831 > * match.pd: Guard simplification to trunc_mod with check for > mod optab support. > > gcc/testsuite/ > PR tree-optimization/116831 > * gcc.dg/torture/pr116831.c: New test. > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew McDonald, Werner Knoblich; (HRB 36809, AG Nuernberg)