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 D9FCD386186E for ; Mon, 16 Oct 2023 21:59:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9FCD386186E 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 D9FCD386186E 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=1697493563; cv=none; b=hvLIB1tV7ivx1/ReJJoADqUu7u/gzuaJCq5b0Lpq8YntE1oEtDGHk5onmJPY572q+lzjEJ1xoTlynXL5glclmpHjgWYrYliamTrpsoVz/K9oTkDVgyE/4byDJuq7AgHXjuEYZelivw3jHoUE9YQkJ8XEbE4bdHtVA+GOoB9rt3Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697493563; c=relaxed/simple; bh=LZ7oUmjpSN3lu5/TqllYIiyyhMFVFDF3bLfhvHQIqTg=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=UaGPcg4eTGRWo0h+jNe4U/0tWcEm6XkOtg4vk8d32UaOmpmnMr14KkoA1YsBWoukfjUONWH+xi4s7XGkmzdY1Duq1vdVqFd4bKOx8bU6ycWX98qurHfWdN/RwsEuZ2GePx6HvRwU31DSzPKdQPcB/zdd0J4gFILCamwfeg9ll9I= 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 02B2A1FB; Mon, 16 Oct 2023 15:00:02 -0700 (PDT) Received: from localhost (unknown [10.32.110.65]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 037A03F762; Mon, 16 Oct 2023 14:59:20 -0700 (PDT) From: Richard Sandiford To: Robin Dapp Mail-Followup-To: Robin Dapp ,Robin Dapp via Gcc-patches , richard.sandiford@arm.com Cc: 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: Mon, 16 Oct 2023 22:59:19 +0100 In-Reply-To: <38b16b69-1b82-420c-839b-d82278515f10@gmail.com> (Robin Dapp's message of "Fri, 13 Oct 2023 17:50:01 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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: 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)) != -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 reflected >> 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 = -vect_xi_13.3_22; > vect_res_2.5_24 = .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 = vect_res_1.0_17 - vect_xi_13.3_22 and then create > vect_res_2.5_24 = 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 = 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 = new_op; > + return gimple_resimplify3 (seq, res_op, valueize); > + } > + else if (seq && *seq && is_gimple_assign (*seq)) > + { > + new_op.code = gimple_assign_rhs_code (*seq); > + new_op.type = res_op->type; > + new_op.num_ops = gimple_num_ops (*seq) - 1; > + new_op.ops[0] = gimple_assign_rhs1 (*seq); > + if (new_op.num_ops > 1) > + new_op.ops[1] = gimple_assign_rhs2 (*seq); > + if (new_op.num_ops > 2) > + new_op.ops[2] = gimple_assign_rhs2 (*seq); > + > + new_op.cond = res_op->cond; > + > + gimple_match_op bla2; > + if (convert_conditional_op (&new_op, &bla2)) > + { > + *res_op = 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. 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_IOR 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 instruction. Thanks, Richard