From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 0CCB4385C6FB for ; Mon, 30 Oct 2023 19:16:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0CCB4385C6FB 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 0CCB4385C6FB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::433 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698693370; cv=none; b=pIVLcK/zo7sJ1+ZCEpwWUhH0G7blSWYllBlqij6vly9vj7aaZiLfGbfGPbVTCdfb8loBLX1/I+YaD0Bu0YJqOL8XQY7FYgibFy+3dUczMJ9S5XjKcqwe/Uy3ynIAifVGp3esXX0d1halxMhbYAEODPJ4w6/lhtAQPLvwsf/wvhw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698693370; c=relaxed/simple; bh=6Ene1DRyfwUpBT59q81dSz1wwbEQNcezbbPiXr/kVrA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=nWKs+0iS81MTYDWYKMargZVFfkRE7QrCXbWya9iFmZiKl63igHRXu0LAXG5MPp3iic2PgNnexFn2jCvlweSXHrRa4AR50k6QlOcjBJYD4F3cSb5jo7R5q7h2EIh0hT2SLuOVgp/0OozsAeRZn9a1+rBkq2NgJoeAMC5/C6v+KCA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6bd32d1a040so4869147b3a.3 for ; Mon, 30 Oct 2023 12:16:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698693368; x=1699298168; 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=0CPJkAYgJa1cf07YvCVMWv03CunrKWBcJhDL6l8ju+M=; b=NNrqzT19TO+MKXe5gUeg1vPGBr9RbC/8v/tPrNFpW2qPTwqz7IkWArkwYrxD1HW7Cz pfaF/+cra0M1/awpzHOkJ5FZlyuU7Y9B+DupV0DE9kJjtgp2D6HsUoKy2z/+EPQfyuOq RSMZ4xF4xAlQ84AqHXKhSnctwRI0ap2lx4O7na4jIW6PgsaEloKjV803sK4gHnZCX/X9 ItX3fYnmg98k1YTOL31K+w3v5E0Ky4dnWD69NshUDUfZZOtiSWMVb0fN0K3EOw6Mkuit EYC0b/NtszZewVfhA5Q1SFqPrBu5yc0tNhM9ZEfGcz6gACFnXcXThqeCr5dFjqyF/5jy xS1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698693368; x=1699298168; 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=0CPJkAYgJa1cf07YvCVMWv03CunrKWBcJhDL6l8ju+M=; b=LN1vg2U/fXIg2gcDtpLJwwkpmnsLwpSeqQi/zMgxTvxzrDd+e0ZQbErwfFHzRrutkt kCAjKhxB3Qwgcs+z+pZ9CVh0x3krCFIanbrZeJTGsVsSvTVj2vN5959TcFTmv/PRSwWu YVV1EuhYTjROn7Kddk3uyAQ46msAj7x7bVSxP4kv5dO4I5iSbwN8eEqT30oQaIRYotx5 SIWNAiY0VUre+quHZqKimoUUyujNWtNxw/SEdDI0RY93LhOB1SIeUEhOI7xc1VreFkmO gqyOYlRprOlmfmhSvp0l5NbV+2BRfSp0t7I2KsowEuZ+e1gJnO4apgByPjEkaef6SJYx b8YA== X-Gm-Message-State: AOJu0YwiqaEfgcH2kE8EMiyUrlNuvoFET5oWk8he2bHewc+9us3YNpwx Ik2Ky+9HkaTgmrszUDXT15s= X-Google-Smtp-Source: AGHT+IFm6ko+lCAJ+aSeBcI34fEATFGzvxGOZAYgkVfXVahbCQQarS3D5nLubRcu2Z9nL1o2oosa6w== X-Received: by 2002:a05:6a00:ccd:b0:6bf:83d1:da6e with SMTP id b13-20020a056a000ccd00b006bf83d1da6emr12257917pfv.22.1698693367832; Mon, 30 Oct 2023 12:16:07 -0700 (PDT) Received: from [172.31.0.109] ([136.36.130.248]) by smtp.gmail.com with ESMTPSA id g11-20020a056a001a0b00b006c1221bc58bsm1693207pfv.115.2023.10.30.12.16.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Oct 2023 12:16:07 -0700 (PDT) Message-ID: Date: Mon, 30 Oct 2023 13:16:02 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/4] [ifcvt] if convert x=c ? y+z : y by RISC-V Zicond like insns Content-Language: en-US To: Fei Gao , gcc-patches@gcc.gnu.org Cc: kito.cheng@gmail.com, palmer@dabbelt.com References: <20231030072523.26818-1-gaofei@eswincomputing.com> <20231030072523.26818-3-gaofei@eswincomputing.com> From: Jeff Law In-Reply-To: <20231030072523.26818-3-gaofei@eswincomputing.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,KAM_SHORT,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 10/30/23 01:25, Fei Gao wrote: > Conditional add, if zero > rd = (rc == 0) ? (rs1 + rs2) : rs1 > --> > czero.nez rd, rs2, rc > add rd, rs1, rd > > Conditional add, if non-zero > rd = (rc != 0) ? (rs1 + rs2) : rs1 > --> > czero.eqz rd, rs2, rc > add rd, rs1, rd > > Co-authored-by: Xiao Zeng > > gcc/ChangeLog: > > * ifcvt.cc (noce_emit_czero): helper for noce_try_cond_zero_arith > (noce_try_cond_zero_arith): handler for condtional zero op > (noce_process_if_block): add noce_try_cond_zero_arith with hook control > > gcc/testsuite/ChangeLog: > > * gcc.target/riscv/zicond_ifcvt_opt.c: New test. > --- > gcc/ifcvt.cc | 112 +++++++++++++++ > .../gcc.target/riscv/zicond_ifcvt_opt.c | 130 ++++++++++++++++++ > 2 files changed, 242 insertions(+) > create mode 100644 gcc/testsuite/gcc.target/riscv/zicond_ifcvt_opt.c > > diff --git a/gcc/ifcvt.cc b/gcc/ifcvt.cc > index a0af553b9ff..4f98c1c7bf9 100644 > --- a/gcc/ifcvt.cc > +++ b/gcc/ifcvt.cc > +static rtx > +noce_emit_czero (struct noce_if_info *if_info, enum rtx_code czero_code, rtx z, rtx target) > +{ > + machine_mode mode = GET_MODE (target); > + rtx cond_op0 = XEXP (if_info->cond, 0); > + rtx czero_cond > + = gen_rtx_fmt_ee (czero_code, GET_MODE (cond_op0), cond_op0, const0_rtx); > + rtx if_then_else = gen_rtx_IF_THEN_ELSE (mode, czero_cond, const0_rtx, z); > + rtx set = gen_rtx_SET (target, if_then_else); > + > + start_sequence (); > + rtx_insn *insn = emit_insn (set); > + > + if (recog_memoized (insn) >= 0) > + { > + rtx_insn *seq = get_insns (); > + end_sequence (); > + emit_insn (seq); > + > + return target; > + } > + > + end_sequence (); > + return NULL_RTX; > +} So just a few notes to further illustrate why I'm currently looking to take the VRULL+Ventana implementation. The code above would be much better handled by just calling noce_emit_cmove. noce_emit_cmove will go through the conditional move expander. So any improvement we make in the expander "just work" when called from the if-converter. > + > /* Try only simple constants and registers here. More complex cases > are handled in noce_try_cmove_arith after noce_try_store_flag_arith > has had a go at it. */ > @@ -2880,6 +2908,88 @@ noce_try_sign_mask (struct noce_if_info *if_info) > return true; > } > > +/* Convert x = c ? y + z : y or x = c ? y : y + z. */ > + > +static bool > +noce_try_cond_zero_arith (struct noce_if_info *if_info) > +{ > + rtx target; > + rtx_insn *seq; > + machine_mode mode = GET_MODE (if_info->x); > + rtx common = NULL_RTX; > + enum rtx_code czero_code = UNKNOWN; > + rtx a = if_info->a; > + rtx b = if_info->b; > + rtx z = NULL_RTX; > + rtx cond = if_info->cond; > + > + if (!noce_simple_bbs (if_info)) > + return false; [ ... ] So the internal code we have does a bit of canonicalization before the optimizing transformations. In particular we may be presented with (a == 0) ? b : a which we transform into (a != 0 ? a : b) which allows us to pick up more cases. (b != 0 ? b : a) gets similar handling. As I mentioned earlier, the VRULL+Ventana code handles wrapping extensions & subregs. Our code also handles if-converting shifts/rotates. Hopefully that explains a bit more why I think cleaning up the VRULL+Ventana code is a better choice. jeff