From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 9BD673857731 for ; Tue, 17 Oct 2023 15:52:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9BD673857731 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9BD673857731 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697557956; cv=none; b=DqVSQWBhUEU6oOJ5aVUPzxKRlGP8bjucsc9/bO2btx3GoUjNvLDUMzclErv2XoaXCQkrEQElZEWnkeCphkd863ExD0QJQc4ezVZCMBu/Fn88U8iICg6jKN4eK3zYOdzKe/MsJJimLJk/jDZ1Z8i5QPPunRjLVZtqX4ABSiLwJfA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697557956; c=relaxed/simple; bh=Cgy8VnHvDgEI6Anh7TjtKSij5QZr+ACWMy1ZpH/rrZM=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=OGWmYioI4LlBrky5epo4k80aoJJsLezECg5EIN7fDyKdx5A96X20VrdA8Zl5lohEHBiLTO+z3JnhibJFCF2ozorxN+bzHEnHJBVyEYgy5U+HifF/FOuP9Q00OruhYkcd06zehOL2VVjOLojZYGniN5YYpcHfMEyTyrZMWE7QpG4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DC9AE2F4; Tue, 17 Oct 2023 08:53:14 -0700 (PDT) Received: from localhost (unknown [10.32.110.65]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id ABD783F762; Tue, 17 Oct 2023 08:52:33 -0700 (PDT) From: Richard Sandiford To: Richard Biener Mail-Followup-To: Richard Biener ,Robin Dapp , Robin Dapp via Gcc-patches , richard.sandiford@arm.com Cc: Robin Dapp , Robin Dapp via Gcc-patches Subject: Re: [PATCH] gimple-match: Do not try UNCOND optimization with COND_LEN. References: <4b77e155-0936-67d6-ab2d-ae7ef49bfde0@gmail.com> <4afb967d-96ea-7e74-1a35-c86aa5a5ffa6@gmail.com> <38b16b69-1b82-420c-839b-d82278515f10@gmail.com> Date: Tue, 17 Oct 2023 16:52:32 +0100 In-Reply-To: (Richard Biener's message of "Tue, 17 Oct 2023 10:47:51 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-18.1 required=5.0 tests=BAYES_00,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Richard Biener writes: > On Mon, Oct 16, 2023 at 11:59=E2=80=AFPM Richard Sandiford > wrote: >> >> Robin Dapp writes: >> >> Why are the contents of this if statement wrong for COND_LEN? >> >> If the "else" value doesn't matter, then the masked form can use >> >> the "then" value for all elements. I would have expected the same >> >> thing to be true of COND_LEN. >> > >> > Right, that one was overly pessimistic. Removed. >> > >> >> But isn't the test whether res_op->code itself is an internal_functio= n? >> >> In other words, shouldn't it just be: >> >> >> >> if (internal_fn_p (res_op->code) >> >> && internal_fn_len_index (as_internal_fn (res_op->code)) !=3D = -1) >> >> return true; >> >> >> >> maybe_resimplify_conditional_op should already have converted to an >> >> internal function where possible, and if combined_fn (res_op->code) >> >> does any extra conversion on the fly, that conversion won't be reflec= ted >> >> in res_op. >> > >> > I went through some of our test cases and believe most of the problems >> > are due to situations like the following: >> > >> > In vect-cond-arith-2.c we have (on riscv) >> > vect_neg_xi_14.4_23 =3D -vect_xi_13.3_22; >> > vect_res_2.5_24 =3D .COND_LEN_ADD ({ -1, ... }, vect_res_1.0_17, vec= t_neg_xi_14.4_23, vect_res_1.0_17, _29, 0); >> > >> > On aarch64 this is a situation that matches the VEC_COND_EXPR >> > simplification that I disabled with this patch. We valueized >> > to _26 =3D vect_res_1.0_17 - vect_xi_13.3_22 and then create >> > vect_res_2.5_24 =3D VEC_COND_EXPR ; >> > This is later re-assembled into a COND_SUB. >> > >> > As we have two masks or COND_LEN we cannot use a VEC_COND_EXPR to >> > achieve the same thing. Would it be possible to create a COND_OP >> > directly instead, though? I tried the following (not very polished >> > obviously): >> > >> > - new_op.set_op (VEC_COND_EXPR, res_op->type, >> > - res_op->cond.cond, res_op->ops[0], >> > - res_op->cond.else_value); >> > - *res_op =3D new_op; >> > - return gimple_resimplify3 (seq, res_op, valueize); >> > + if (!res_op->cond.len) >> > + { >> > + new_op.set_op (VEC_COND_EXPR, res_op->type, >> > + res_op->cond.cond, res_op->ops[0], >> > + res_op->cond.else_value); >> > + *res_op =3D new_op; >> > + return gimple_resimplify3 (seq, res_op, valueize); >> > + } >> > + else if (seq && *seq && is_gimple_assign (*seq)) >> > + { >> > + new_op.code =3D gimple_assign_rhs_code (*seq); >> > + new_op.type =3D res_op->type; >> > + new_op.num_ops =3D gimple_num_ops (*seq) - 1; >> > + new_op.ops[0] =3D gimple_assign_rhs1 (*seq); >> > + if (new_op.num_ops > 1) >> > + new_op.ops[1] =3D gimple_assign_rhs2 (*seq); >> > + if (new_op.num_ops > 2) >> > + new_op.ops[2] =3D gimple_assign_rhs2 (*seq); >> > + >> > + new_op.cond =3D res_op->cond; >> > + >> > + gimple_match_op bla2; >> > + if (convert_conditional_op (&new_op, &bla2)) >> > + { >> > + *res_op =3D bla2; >> > + // SEQ should now be dead. >> > + return true; >> > + } >> > + } >> > >> > This would make the other hunk (check whether it was a LEN >> > and try to recreate it) redundant I hope. >> > >> > I don't know enough about valueization, whether it's always >> > safe to do that and other implications. On riscv this seems >> > to work, though and the other backends never go through the LEN >> > path. If, however, this is a feasible direction it could also >> > be done for the non-LEN targets? >> >> I don't know much about valueisation either :) But it does feel >> like we're working around the lack of a LEN form of COND_EXPR. >> In other words, it seems odd that we can do: >> >> IFN_COND_LEN_ADD (mask, a, 0, b, len, bias) >> >> but we can't do: >> >> IFN_COND_LEN (mask, a, b, len, bias) >> >> There seems to be no way of applying a length without also finding an >> operation to perform. > > Indeed .. maybe - _maybe_ we want to scrap VEC_COND_EXPR for > IFN_COND{,_LEN} to be more consistent here? Yeah, sounds like it could be worthwhile. But I suppose we still need VEC_COND_EXPR itself because it's a generic front-end operation that needs to be lowered. So it might be worth starting with an ifn for the LEN form and seeing whether the non-LEN form should switch over. Thanks, Richard