From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 015633858C35 for ; Tue, 17 Oct 2023 08:50:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 015633858C35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 015633858C35 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::12c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697532652; cv=none; b=EkxNVoRpKd/v5pyRD0MEZmlPH+kizbuiCP0yOI+gKaU/XCIBdUerGKdVEvbO4lO0caFpRvDz2uiqT/PjHQ1xLgvOFQ1po+hNVQBWvBkFyC2ehKR329Null6OUZ6UO5MTbRHn4SxEPE3ZDrV3ukQtxMLJmUZH9nZwaK0mZQkh0Zs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697532652; c=relaxed/simple; bh=m+R3PfjoQdVi7uBRQHl4hwK8eKKDsgYAIlLHJrsZv2I=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=kScErmkCzOzjmhHiF9JztfObOxlvrlMYg8XYwZH+ARS9fAQRujqa9SDLcQsIH+booiSyG/Tg6P9ZvvhIqAtnt6glUEAAzf1lKaxLePODUXiuEA6u6IGYiGk14l4fJ+ZDpr0yM6qZpezqk5KK2qASR1PcA9ET43vzz1yzOS+C7SI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-50435a9f800so6778716e87.2 for ; Tue, 17 Oct 2023 01:50:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697532649; x=1698137449; darn=gcc.gnu.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=WR3kCrrKefWiIYk9dhMtTREsCtDGnULmud5BE6EXVAA=; b=AgCc0Lpi0RcrlhGT/zfMtRu1TjHKpWzMRxSgnpfZJw5wTf2EW48SgT1LUdYrGYZZK4 ijNSr0jXM3nH5K/O+SRpey+a7Ur6XekhnTWuFmoOsY+pCncVl/6e7jDUeNUFEs8RUfZ+ uNBgFttUvOdM14v5QCZ94QKLuk+kcHY831P6PDrewNOvrT46lQQvLEznthpgIgTMbyqq ey0NFJR7gQCurEWzIMDKqOfkLwQ/0S+VZtndMZTRM20/z5XOZ2lq9uP5xQnRywcEsJ9L DpIsbZ2DN5J/pLgbcxks6lzVNf6MowHRMzz/frAem1S46RmMQa6R+V7pkoXgLzh4Bnvy Ikzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697532649; x=1698137449; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WR3kCrrKefWiIYk9dhMtTREsCtDGnULmud5BE6EXVAA=; b=wrrrzxrw1fIrYFpDfPhd8YQb1aoRB+qkzKHP7AM1/Iyjcsp+5w0l4yUSFHnGHYzU12 Q0XlXmGl3z5y8r7U1SG2Slmz4RaHXE9vYhO6/mxuJakV1q9sCZIPEiz8hK4KV5dF1toi R9FW8pFqMAY0Jsog2pyVfbb70EyAxG6811qNUOKVPNTI1RSMkAb5egBFOPbhirBtJLaK KqYiD4IbYJuMpavDnISFiNKIdB2Pg2yvHVPBHIMFPO0PvUIbrEYGwKker/ggemjoINNb mvQEDaY17IPmLoOSVBNXhEm6XWZ+8S8ZFo5tbqQ1kNVX78iJHEy80UOx4O+/5jkomjoz bPnQ== X-Gm-Message-State: AOJu0YycOvS0sscE1pbZXbR+rs77PFxpucytyLOfH7NvMeVcnI1xpLRZ UfBk9ZaUt09lYrZJdNWH9XD3aHjUAOv1/LHxRbLgj9Ze X-Google-Smtp-Source: AGHT+IHKxHRcHa2f1pLL4LxwsMOL9bDvw4+gPjMQx6bOHQVcaqsU0fnzT9Zy+RBarX977n8kCSyIK0K9Jh+9ZP31kD4= X-Received: by 2002:a19:4f57:0:b0:507:b35d:833b with SMTP id a23-20020a194f57000000b00507b35d833bmr1376461lfk.14.1697532648942; Tue, 17 Oct 2023 01:50:48 -0700 (PDT) MIME-Version: 1.0 References: <4b77e155-0936-67d6-ab2d-ae7ef49bfde0@gmail.com> <4afb967d-96ea-7e74-1a35-c86aa5a5ffa6@gmail.com> <38b16b69-1b82-420c-839b-d82278515f10@gmail.com> In-Reply-To: From: Richard Biener Date: Tue, 17 Oct 2023 10:47:51 +0200 Message-ID: Subject: Re: [PATCH] gimple-match: Do not try UNCOND optimization with COND_LEN. To: Robin Dapp , Robin Dapp via Gcc-patches , richard.sandiford@arm.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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_function= ? > >> 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 reflect= ed > >> 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, vect= _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? > Does IFN_COND_LEN make conceptual sense on RVV? If so, would defining > it solve some of these problems? > > I suppose in the worst case, IFN_COND_LEN is equivalent to IFN_COND_LEN_I= OR > with a zero input (and extended to floats). So if the target can do > IFN_COND_LEN_IOR, it could implement IFN_COND_LEN using the same instruct= ion. In principle one can construct a mask from the length via {0, 1, ... } < len and then AND that to the mask in a VEC_COND_EXPR but that's of course super ugly and likely inefficient (or hard to match back on RTL land). Richard. > Thanks, > Richard >