On Wed, May 4, 2022 at 12:16 PM Richard Earnshaw via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > > Gimple isel already handles x CMP y ? -1 : 0 when lowering vector cond > operations, but this can be generalized further when the comparison > forms a natural mask so that we can also handle x CMP y ? z : 0 by > transforming it into (x CMP y) & z. This will, in most cases save > having to load a register with the zero vector.
Hmm, I'm not sure why exactly the existing case is in ISEL but if we want to extend it there we migh also want to handle ? 0 : -1 as BIT_NOT. For the case in question it looks like it might better fit as optimization in match.pd? It also lacks a query for present and<mode>3 support. For match.pd it might be nice to handle x CMP y ? 0 : z as well if we can invert x CMP y (and it has only a single use). When in ISEL we might as well check for andn<mode>3 support and go with BIT_NOT + BIT_AND ... Do you have a testcase where it improves code generation btw? Richard. > gcc/ChangeLog: > * gimple-isel.cc (gimple_expand_vec_cond_expr): Handle > x CMP y ? z : 0. > --- > gcc/gimple-isel.cc | 29 +++++++++++++++++++++++------ > 1 file changed, 23 insertions(+), 6 deletions(-) >