From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by sourceware.org (Postfix) with ESMTPS id D95A83858D33 for ; Sun, 19 Nov 2023 17:45:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D95A83858D33 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 D95A83858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:4860:4864:20::2d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700415924; cv=none; b=vO6b9aXgW2r27Lj1wa2rjBrRX61ZyNVCfgxrawpw5kOOZO8upwz/ArxkFlqFmU4maVuL/1v+tzTFyZhtCxpg6Lsv1Qn9rSDwlQnYExDeiGLUzLOT8x+flv95JlnzcYS1BvFs5QDIv7YruO3j368Bj9hNQfic/K72eb1OzjS71Ow= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700415924; c=relaxed/simple; bh=rk6je+IWWMhU/GBclJPiJE9tLUBJvY/PfIDwGT5XirQ=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=jvcvPnrq/UC53oNLyAxRbYkiBo0xSZY52y1dhHW4+OQZ9XubL6N0K8I8aTLk9eFO1Hb5XN3t/hy/g4CYu5V8V20yRB0X/fydbSiW5bxsNgOe6QJx2zDgCgUUQsh1bO74pA5ennxWlFXtyB9azpXgQ3r/3yvNcVYZEl07K+C4qKo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-1f03db0a410so2161126fac.1 for ; Sun, 19 Nov 2023 09:45:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700415922; x=1701020722; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=baRX1FUSEXXVZL/ikdDjegvQF236iUp+0tosslogl0k=; b=fanQfFVyidYhqSbYTQiS3vCN8uOWafMdBQNiySLkhv8TY60C0VdE9nSa/J3oVD1kd9 mPtYapBuj4YaadyhWSmkr8w9GLNXEcH3T+J0eyPe3kXLSUJ0oZtmBC9z4X5UbvHHpwMs heqTCJNIrtcDDlk1NE+E3r5F7x4RwkekWKJ2jltysBmmP3rVaJ4W21mZpsKpEBfzHeCk acIqKtvBilKYK/hAJa4tvTPhawGy2sKSgpKCkk1S8YKmBbo6Hjk11VO72W0fHdAWvzJu TT96pTvFLRhOlyYZsExBsAh3vyivUAn4akntHqszLZ8wNHsx4IljiTC/9pu83N2n4TqW cTxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700415922; x=1701020722; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=baRX1FUSEXXVZL/ikdDjegvQF236iUp+0tosslogl0k=; b=NKbwcC+nJv2QyosfWyjlHADf2uMZbyik0nAWhBGIC7JEowfM/mN81x/ps+kK3WXVWc ANGuINecv6zeMkx3tEr4EwsHf5zy4LB5v+s90F4+jM4Yy8SxbvY0SE2iimhUm9VRhLB7 fmTFCr25I5s+Vy5LlFiXzBgyk+ClcPiDFWjgg4i+Ji4euujhRQQhcDoi/ellxOxsj83c IoF+OHeqbEGk59pGo4Hyn9q7mLGarBWprWTWnvHezsqkTDPyh/TSENDSWvv4BKfXvE6w +QzJw/2yQA9lpC5Qxh6Ss0RKtPAEdohOSYi33noBPzXcpGnPmYHmHJRUV7OI8vnBLS0G 6mEA== X-Gm-Message-State: AOJu0Yyvnr12QnULAGY9752MuNBhQIG6RpqaqFhxuxETQJF4ggZtRNtP gptCgLtCYdjA0THHQjxH4BPJ0BM3A1bgtQ== X-Google-Smtp-Source: AGHT+IHPyTtFH6XC3Eeo29SsQWxk38B1/7+FMztcwXI9EdEMHb58z4QCxoF+sIJpeUX5gcwDFr5ShQ== X-Received: by 2002:a05:6871:4e85:b0:1e9:bd5c:ae40 with SMTP id uk5-20020a0568714e8500b001e9bd5cae40mr6072482oab.38.1700415922215; Sun, 19 Nov 2023 09:45:22 -0800 (PST) Received: from [172.31.0.109] ([136.36.130.248]) by smtp.gmail.com with ESMTPSA id i2-20020a056870a68200b001ef38a85f9bsm1045234oam.16.2023.11.19.09.45.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 19 Nov 2023 09:45:21 -0800 (PST) Message-ID: <3e266273-0110-4a9e-8786-8afe71c490cb@gmail.com> Date: Sun, 19 Nov 2023 10:45:20 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 17/44] RISC-V: Avoid extraneous EQ or NE operation in cond-move expansion Content-Language: en-US To: "Maciej W. Rozycki" , gcc-patches@gcc.gnu.org Cc: Andrew Waterman , Jim Wilson , Kito Cheng , Palmer Dabbelt References: From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URIBL_BLACK 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: On 11/18/23 22:38, Maciej W. Rozycki wrote: > In the non-zero case there is no need for the conditional value used by > Ventana and Zicond integer conditional operations to be specifically 1. > Regardless we canonicalize it by producing an extraneous conditional-set > operation, such as with the sequence below: > > (insn 22 6 23 2 (set (reg:DI 141) > (minus:DI (reg/v:DI 135 [ w ]) > (reg/v:DI 136 [ x ]))) 11 {subdi3} > (nil)) > (insn 23 22 24 2 (set (reg:DI 140) > (ne:DI (reg:DI 141) > (const_int 0 [0]))) 307 {*sne_zero_didi} > (nil)) > (insn 24 23 25 2 (set (reg:DI 143) > (if_then_else:DI (eq:DI (reg:DI 140) > (const_int 0 [0])) > (const_int 0 [0]) > (reg:DI 13 a3 [ z ]))) 27913 {*czero.eqz.didi} > (nil)) > (insn 25 24 26 2 (set (reg:DI 142) > (if_then_else:DI (ne:DI (reg:DI 140) > (const_int 0 [0])) > (const_int 0 [0]) > (reg/v:DI 137 [ y ]))) 27914 {*czero.nez.didi} > (nil)) > (insn 26 25 18 2 (set (reg/v:DI 138 [ z ]) > (ior:DI (reg:DI 142) > (reg:DI 143))) 105 {iordi3} > (nil)) > > where insn 23 can well be removed without changing the semantics of the > sequence. This is actually fixed up later on by combine and the insn > does not make it to output meaning no SNEZ (or SEQZ in the reverse case) > appears in the assembly produced, however it counts towards the cost of > the sequence calculated by if-conversion, raising the trigger level for > the branchless sequence to be chosen. Arguably to emit this extraneous > operation it can be also considered rather sloppy of our backend's. > > Remove the check for operand 1 being constant 0 in the Ventana/Zicond > case for equality comparisons then, observing that `riscv_zero_if_equal' > called via `riscv_emit_int_compare' will canonicalize the comparison if > required, removing the extraneous insn from output: > > (insn 22 6 23 2 (set (reg:DI 142) > (minus:DI (reg/v:DI 135 [ w ]) > (reg/v:DI 136 [ x ]))) 11 {subdi3} > (nil)) > (insn 23 22 24 2 (set (reg:DI 141) > (if_then_else:DI (eq:DI (reg:DI 142) > (const_int 0 [0])) > (const_int 0 [0]) > (reg:DI 13 a3 [ z ]))) 27913 {*czero.eqz.didi} > (nil)) > (insn 24 23 25 2 (set (reg:DI 140) > (if_then_else:DI (ne:DI (reg:DI 142) > (const_int 0 [0])) > (const_int 0 [0]) > (reg/v:DI 137 [ y ]))) 27914 {*czero.nez.didi} > (nil)) > (insn 25 24 18 2 (set (reg/v:DI 138 [ z ]) > (ior:DI (reg:DI 140) > (reg:DI 141))) 105 {iordi3} > (nil)) > > while keeping actual assembly produced the same. > > Adjust branch costs across the test cases affected accordingly. > > gcc/ > * config/riscv/riscv.cc (riscv_expand_conditional_move): Remove > the check for operand 1 being constant 0 in the Ventana/Zicond > case for equality comparisons. > > gcc/testsuite/ > * gcc.target/riscv/zicond-primitiveSemantics_compare_imm_return_imm_imm.c: > Lower `-mbranch-cost=' setting. > * gcc.target/riscv/zicond-primitiveSemantics_compare_imm_return_imm_reg.c: > Likewise. > * gcc.target/riscv/zicond-primitiveSemantics_compare_imm_return_reg_reg.c: > Likewise. > * gcc.target/riscv/zicond-primitiveSemantics_compare_reg_return_imm_imm.c: > Likewise. > * gcc.target/riscv/zicond-primitiveSemantics_compare_reg_return_imm_reg.c: > Likewise. > * gcc.target/riscv/zicond-primitiveSemantics_compare_reg_return_reg_reg.c: > Likewise. OK. Thanks for catching this! jeff