Message ID | alpine.DEB.2.20.2311182249380.5892@tpp.orcam.me.uk |
---|---|
State | Unresolved |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1506550vqn; Sat, 18 Nov 2023 21:43:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IH77Hvz98ny60tImQFR089K6nXpe9osSTij3b5FEsKNBTFtOkPMquRn8WHGtAf4L+xoZMpa X-Received: by 2002:a05:620a:5237:b0:76c:ea67:38e4 with SMTP id dc55-20020a05620a523700b0076cea6738e4mr5248938qkb.12.1700372632390; Sat, 18 Nov 2023 21:43:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700372632; cv=pass; d=google.com; s=arc-20160816; b=ZESS7bQtoDivjGqFLP8ixCjOCDwfH9Lp20d+rVXaUMkCLdpuG863mGxZBajTQV/7vx 3BWH3AiVXzrmrFsm7MhFSkbnP7r8PPaGTyibRfSUSEePfreg696IMAEbGjMsrwPtDHFJ TIYgAFKiL2WlKvJEfX2F9T4CXHqBe6F5SyCU5Ttf0dmyeqqpIbJkSjRqNIwsFkt2FfPC g9gr8PXl4h88omY+vU59sE32OysPJRhqb8u8m8mqkJhWl5JIvfDz7dyeMf8NZlpYozFM KPqiNtxhjwBP5JxbfQAdUUn2bdGuT49lrP7dyXltlmINKdQRJg7M5dbRO24gyPGUsPza aMvg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:user-agent :references:message-id:in-reply-to:subject:cc:to:from:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=kX1Drrn7DLJVjSndEmo9/4eLYNECZJhrr3HKms+85mQ=; fh=dp1z4I3tVhinwswv7IAFxpunWK+Ws/fGQfmox9vHv3I=; b=VKVNq0duIqwy9m2hrURs+OKw+d94IY2BhlrHE3oyEDhDRPWRrEFlv+rW9HhPw37rsD Z3Ic0BD6YpqB264+znDN/SmgX2GxFSRL/ASxmZKH61sB9uxxcPd+nMdR1ZnejEbdyvks HiHEReyADqGw1l/1NWO5hpsHPbIqk2DOuvi+W6QlOtsbxqNCp8g5d5VboRrRv9Ku31uu wAXZcqHgcAJYvsiPpf0GuRNtEipnMenvIno5PuoD3r1GCFiLfkaEEdHUJIkmWmppDXaY Bhsqk7QRwagQFug72zHULqLkvyf4VZ6K05UPHC0Jll7EtaUoWW+enj8P3NTwy8VoxNoE xevw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=OlaStFNP; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id oq8-20020a05620a610800b0076762f87d06si4570444qkn.784.2023.11.18.21.43.52 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 21:43:52 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=OlaStFNP; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC885385B53C for <ouuuleilei@gmail.com>; Sun, 19 Nov 2023 05:43:38 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) by sourceware.org (Postfix) with ESMTPS id C54E83858432 for <gcc-patches@gcc.gnu.org>; Sun, 19 Nov 2023 05:42:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C54E83858432 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embecosm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org C54E83858432 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::529 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700372563; cv=none; b=PMPgsm6/c7l5Tnxf+evWo7idCMsYICdsJ3DD/jjNDtXpP0XppdrZ2wWGMVi16/aISPEhAdXOrCEu2Tn7mC8t4X0yomAVqWcojIaRJka9588TOCpFnsTb8+NIsuHwbJHb4p2NOqBV4uBG3zNTzhx/LKk3M3xJvmO392wCvHeSsfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700372563; c=relaxed/simple; bh=z/HiTSwamZ1rQFa5AwuZzHaaeos7X8n7jdUAZcaB6M4=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=RvEHksG4B1768eC6tLcdLGOhXo8THYegQMfFXslq4csDDZZ1ohfkt/nn3mafmUzEiyIo317P9lkQZQU0Q6TiJaBjYhkZKWIIjDy5534lnBrJXYUf4hFYSNDBv5ymYn8D0+xCd6Set8pu2cdgL5rwAVlEaYxXyZ4YuU32SgW0QIc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x529.google.com with SMTP id 4fb4d7f45d1cf-53e04b17132so4711391a12.0 for <gcc-patches@gcc.gnu.org>; Sat, 18 Nov 2023 21:42:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1700372560; x=1700977360; darn=gcc.gnu.org; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=kX1Drrn7DLJVjSndEmo9/4eLYNECZJhrr3HKms+85mQ=; b=OlaStFNPyjY4xSTZsGhz0LJJOrFYzLOsQ68QlbLDd/ulg7qQtEUB0eMZ+aii2qKxwC bjeEx4455+08tCFOadtngUA0IHtAjDWM23c1O4J627rHqe2kaTUvhlv8sOfuro1hMxBg Z1723Rl5b94al7WKmNh0y9bsKzgE7hoIfuEzcWm+tshYGDsGuabax+NTACC4gERllRbE 3Acoz6u8daYOfSejCXJQ82lfi4HwFRp/08EIXCAgwJ39ma6n2IlrUCUKBDvRmqpdCoyV 3bC/hg+0DUOo02yw4WZbm0admSgO16zfkjz3syxnpSmUNw0+C0Ruf/GRgCeG6r1yB0vA 94sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700372560; x=1700977360; h=mime-version:user-agent:references:message-id:in-reply-to:subject :cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=kX1Drrn7DLJVjSndEmo9/4eLYNECZJhrr3HKms+85mQ=; b=gkXyZw1gZB9jOh64XX/hBIe70CiZV91c911HiXVRmsQBbYT/zCC2HAFoIOu+o005dr auU/IpYgYNwSe/VmKB7du3h0o+eo0uz3N5wMONQB/Es6NOjGeM5bQi/opWYmUvw8eGXq xUTwta+rtBp4J/xV0g18jVpVsXbvOWs8F0R9ALw0oNnNpCOGXvQ2M8USF5fy3hu/zte1 5RqSdaOb7gk8sIFKEL4QuDnSmiWCrDcUUE1vKC8Lj5fWcic9N4tYlqQXpWEarhmYqqat 5mCqhbCXe5ni1nACnaQhKxwPRroJ6rGwXEYdVvUk1jeGYuW2lWWeqeYK22hdkmgDfiKc Y3Ww== X-Gm-Message-State: AOJu0Yz7ffT8leoa/lmTHQfp6ysqmgQ8whewyRQd0VCQpJz1H4QFVyFR tc/7OobfII8+oT1A/8TFef40wy9Ki/5WjS6ZDGzaZQ== X-Received: by 2002:a17:907:11c9:b0:9be:30c2:b8fd with SMTP id va9-20020a17090711c900b009be30c2b8fdmr2685606ejb.66.1700372560517; Sat, 18 Nov 2023 21:42:40 -0800 (PST) Received: from [192.168.219.3] ([78.8.192.131]) by smtp.gmail.com with ESMTPSA id rs15-20020a170907036f00b009e62bb0439bsm2525676ejb.212.2023.11.18.21.42.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Nov 2023 21:42:40 -0800 (PST) Date: Sun, 19 Nov 2023 05:42:37 +0000 (GMT) From: "Maciej W. Rozycki" <macro@embecosm.com> To: gcc-patches@gcc.gnu.org cc: Andrew Waterman <andrew@sifive.com>, Jim Wilson <jim.wilson.gcc@gmail.com>, Kito Cheng <kito.cheng@gmail.com>, Palmer Dabbelt <palmer@dabbelt.com> Subject: [PATCH 35/44] RISC-V: Avoid extraneous integer comparison for FP comparisons In-Reply-To: <alpine.DEB.2.20.2311171315580.5892@tpp.orcam.me.uk> Message-ID: <alpine.DEB.2.20.2311182249380.5892@tpp.orcam.me.uk> References: <alpine.DEB.2.20.2311171315580.5892@tpp.orcam.me.uk> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782969933248908875 X-GMAIL-MSGID: 1782969933248908875 |
Series |
RISC-V: Various if-conversion fixes and improvements
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | warning | Git am fail log |
Commit Message
Maciej W. Rozycki
Nov. 19, 2023, 5:42 a.m. UTC
We have floating-point coditional-set machine instructions for a subset of FP comparisons, so avoid going through a comparison against constant zero in `riscv_expand_float_scc' where not necessary, preventing an extraneous RTL instruction from being produced that counts against the cost of the replacement branchless code sequence in if-conversion, e.g.: (insn 29 6 30 2 (set (reg:DI 142) (ge:DI (reg/v:DF 135 [ w ]) (reg/v:DF 136 [ x ]))) 297 {*cstoredfdi4} (nil)) (insn 30 29 31 2 (set (reg:DI 143) (ne:DI (reg:DI 142) (const_int 0 [0]))) 319 {*sne_zero_didi} (nil)) (insn 31 30 32 2 (set (reg:DI 141) (reg:DI 143)) 206 {*movdi_64bit} (nil)) (insn 32 31 33 2 (set (reg:DI 144) (neg:DI (reg:DI 141))) 15 {negdi2} (nil)) (insn 33 32 34 2 (set (reg:DI 145) (and:DI (reg:DI 144) (reg/v:DI 137 [ y ]))) 102 {*anddi3} (nil)) (insn 34 33 35 2 (set (reg:DI 146) (not:DI (reg:DI 144))) 111 {one_cmpldi2} (nil)) (insn 35 34 36 2 (set (reg:DI 147) (and:DI (reg:DI 146) (reg/v:DI 138 [ z ]))) 102 {*anddi3} (nil)) (insn 36 35 21 2 (set (reg/v:DI 138 [ z ]) (ior:DI (reg:DI 145) (reg:DI 147))) 105 {iordi3} (nil)) where the second insn effectively just copies its input. This now gets simplified to: (insn 29 6 30 2 (set (reg:DI 141) (ge:DI (reg/v:DF 135 [ w ]) (reg/v:DF 136 [ x ]))) 297 {*cstoredfdi4} (nil)) (insn 30 29 31 2 (set (reg:DI 142) (neg:DI (reg:DI 141))) 15 {negdi2} (nil)) (insn 31 30 32 2 (set (reg:DI 143) (and:DI (reg:DI 142) (reg/v:DI 137 [ y ]))) 102 {*anddi3} (nil)) (insn 32 31 33 2 (set (reg:DI 144) (not:DI (reg:DI 142))) 111 {one_cmpldi2} (nil)) (insn 33 32 34 2 (set (reg:DI 145) (and:DI (reg:DI 144) (reg/v:DI 138 [ z ]))) 102 {*anddi3} (nil)) (insn 34 33 21 2 (set (reg/v:DI 138 [ z ]) (ior:DI (reg:DI 143) (reg:DI 145))) 105 {iordi3} (nil)) lowering the cost of the code sequence produced (even though combine would swallow the second insn anyway). We still need to produce a comparison against constant zero where the instruction following a floating-point coditional-set operation is a branch, so add canonicalization to `riscv_expand_conditional_branch' instead. gcc/ * config/riscv/riscv.cc (riscv_emit_float_compare) <NE>: Handle separately. <EQ, LE, LT, GE, GT>: Return operands supplied as is. (riscv_emit_binary): Call `riscv_emit_binary' directly rather than going through a temporary register for word-mode targets. (riscv_expand_conditional_branch): Canonicalize the comparison if not against constant zero. --- gcc/config/riscv/riscv.cc | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) gcc-riscv-emit-float-compare-fcmp.diff
Index: gcc/gcc/config/riscv/riscv.cc =================================================================== --- gcc.orig/gcc/config/riscv/riscv.cc +++ gcc/gcc/config/riscv/riscv.cc @@ -4029,9 +4029,10 @@ riscv_emit_float_compare (enum rtx_code #undef UNORDERED_COMPARISON case NE: - fp_code = EQ; *code = EQ; - /* Fall through. */ + *op0 = riscv_force_binary (word_mode, EQ, cmp_op0, cmp_op1); + *op1 = const0_rtx; + break; case EQ: case LE: @@ -4039,8 +4040,9 @@ riscv_emit_float_compare (enum rtx_code case GE: case GT: /* We have instructions for these cases. */ - *op0 = riscv_force_binary (word_mode, fp_code, cmp_op0, cmp_op1); - *op1 = const0_rtx; + *code = fp_code; + *op0 = cmp_op0; + *op1 = cmp_op1; break; case LTGT: @@ -4080,10 +4082,14 @@ riscv_expand_float_scc (rtx target, enum { riscv_emit_float_compare (&code, &op0, &op1); - rtx cmp = riscv_force_binary (word_mode, code, op0, op1); - if (GET_MODE (target) != word_mode) - cmp = lowpart_subreg (GET_MODE (target), cmp, word_mode); - riscv_emit_set (target, cmp); + machine_mode mode = GET_MODE (target); + if (mode != word_mode) + { + rtx cmp = riscv_force_binary (word_mode, code, op0, op1); + riscv_emit_set (target, lowpart_subreg (mode, cmp, word_mode)); + } + else + riscv_emit_binary (code, target, op0, op1); } /* Jump to LABEL if (CODE OP0 OP1) holds. */ @@ -4096,6 +4102,13 @@ riscv_expand_conditional_branch (rtx lab else riscv_emit_int_compare (&code, &op0, &op1); + if (FLOAT_MODE_P (GET_MODE (op0))) + { + op0 = riscv_force_binary (word_mode, code, op0, op1); + op1 = const0_rtx; + code = NE; + } + rtx condition = gen_rtx_fmt_ee (code, VOIDmode, op0, op1); emit_jump_insn (gen_condjump (condition, label)); }