From patchwork Sun Nov 19 05:40:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Maciej W. Rozycki" X-Patchwork-Id: 166694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1505706vqn; Sat, 18 Nov 2023 21:40:32 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmGsKzdR4QgfItR/i1zmqJcp9p+/9ZVQDpzw+lBwMXByUnr6DqAG1EuwF/eyQAIARhzkh+ X-Received: by 2002:a05:620a:8007:b0:777:326d:83de with SMTP id ee7-20020a05620a800700b00777326d83demr4499230qkb.56.1700372432024; Sat, 18 Nov 2023 21:40:32 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700372432; cv=pass; d=google.com; s=arc-20160816; b=mDNWRS94odbO8gBLIPRulKwtZoZMVGUw9O4QCQdxe+MiT7+WV+jNHzSKTL88jtfU5e ITfnZ2nyoDHZ0n8R30IXCjLr4g2RN/bgbqQ3xGY2E6H3TuSydF+9br/kFqlbl7O8cyPF M7jKtwhY6lPcIoPAvoFkIDpQG6aZaSh4nPl+HhOA1m7vDsdTk2xTjdnyiuDyym+V29ZN zmD076ooRjM1QJ/G7Tg/j8WuIeIZ90+1wfoOYM0+qUbqDj3yFJwQ3iTxKbZPbPOrgdf3 cjBPSa+m7HjU8cT+ydaa/U9xHG44NgEYFJaJUq82Y1mYZ5V01WPnVXAQErEE6DkKbC1U uulw== 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=V9Px6vKIy8MDU4iw0UgQYRADuU9oUJCS1OBbpJwDd/k=; fh=dp1z4I3tVhinwswv7IAFxpunWK+Ws/fGQfmox9vHv3I=; b=p3dZPgzsf5biSP4jbzWRjA+n/5ZlQ1ft4Ka5MiaG0FsiYOTvp9wa6UFMMa5leIYcws OnqCVwCIjPe5l58wdZxLGYQc3sATfV+VMzvFr+GserP0XiZoKKBwmRq93J25JSy8WS/e zaMKBEWca1hGFrlXWa+y4CFye0Y68KIzV0sv6JN3PDsLnfmW4/uGACfL61pCGuV5ulnr G/eQ1SiPswk+dJz0wl4A4bM1hCYCUx+vnAYXQojlCFZVDtaRHEU0pp/ZimjnKwPqWW3A Ru9Imm9faaMazBeBOfgiu6XLawlaWxmS61mn8FOwqjVuKAHV8hU+Sjw8L5fgJy/XQhQE OEiQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@embecosm.com header.s=google header.b=JHaVCk97; 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 br38-20020a05620a462600b00775bfe3a8f7si5191768qkb.410.2023.11.18.21.40.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 21:40:32 -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=JHaVCk97; 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 C6D3F38582A3 for ; Sun, 19 Nov 2023 05:40:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 54C92385840D for ; Sun, 19 Nov 2023 05:40:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 54C92385840D 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 54C92385840D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::636 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700372409; cv=none; b=eLRru8YDo7vVA0jBUWH5AbscB2eV1aGQj37i6FlsBmSCSP1nQ7vMpZO0BbkKv2BFVF+cI9NI+O4ZbaKw7ryRpOW4rwQBgcXkFzLiie2Iin3m9cCJgt+8c7heLcI42K9dkvzPE6X9uWQLL2KsJlT+C35HOgfbJBbML2UZlN8Gqpc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700372409; c=relaxed/simple; bh=hBkp645S3jveTqUl4tANojSFkdrif+163c/8/zIHKyw=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=OJouvXYGZSILNI5ZJFVd69ftssr3kM4PeOtxvYeltLS99dqKj47+2Cz8dHHDVFKcnKtDIMhY/cLlSWStTidg1q4l46wmm+acBIkrRRz/W+uYXavWg5DbGMO9VgjD1jLBk4G3JiiQY38QjZ4CWka4aUS++1a9FXFi+z3+YYzf0Ks= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x636.google.com with SMTP id a640c23a62f3a-9e62ab773f1so460271266b.0 for ; Sat, 18 Nov 2023 21:40:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; t=1700372406; x=1700977206; 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=V9Px6vKIy8MDU4iw0UgQYRADuU9oUJCS1OBbpJwDd/k=; b=JHaVCk97UaBdGuzHZliWWAd7LEVlEYTyHYYxnEQLaZey+wGIlHfIziATIwcCTuEt4V LHr1c48ei+TQwi2525YTr4JMz5eCq3Ki5b8CtIZkPuowyVeDqWcNQAy3IQ3fuzixBNGC VqPQIaOfRdwlrzNwzORTmQcCc1Dpz/ND5V+Lqy2iYpF1uVMB/peJWNJoio3Ur06ndKAR iNhqdvx4ATGET3yVFKyrQ9dtGMHfYBhW0djh4Zj+XSy5Uo7Cx+eeGChlIdVaN7uLCCub me1mD6OwwZlAu8M3tJpeWV7ou3qxyn3zwZj1vJsdxrlzYyzfYBMBEbuTnVcGtzGebrmF 596w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700372406; x=1700977206; 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=V9Px6vKIy8MDU4iw0UgQYRADuU9oUJCS1OBbpJwDd/k=; b=akkrwatPJzsIUQJG/MsEXb8PB3+wlX458k+2EmJE2xRizin3/e4VwFXIzhfybBfZ0l PlZ/iX+GAiGODyno0T7yKXf40zrIFliYKDAHYx0wxBerNvPkUi5FkEwrcqx7OreoYsR/ nSQ49g/L9jkZsFZowtMhAUjVWmeRvze7bBweICUJgi1SL59KlOOnCceDSe7fyuSIRhPM hsXOPg8H0C3El2Twnc5t/fGeEGCzrVUrXF8U0BeQ5MzbdKn4Cl4wXFlFEJvszYF2SuU7 Au7zUX7pdnVZKxDavKNMtn97D8epQfX41+s1p6iooo0Jckzz8zYtRptPmkF/QIDgPiMc Pzfw== X-Gm-Message-State: AOJu0Yw9pKw7ftC0fmi8gRLwZECFBvyLfGitGqs0EFC0U8NwwB+NgGXs 5IHWDLpc0xaZdDF8vCxSzRg1KUTvtThGUnzzTdzjvw== X-Received: by 2002:a17:906:dfe2:b0:9bd:9bfe:e40b with SMTP id lc2-20020a170906dfe200b009bd9bfee40bmr2808779ejc.75.1700372405994; Sat, 18 Nov 2023 21:40:05 -0800 (PST) Received: from [192.168.219.3] ([78.8.192.131]) by smtp.gmail.com with ESMTPSA id h19-20020a170906585300b00982a92a849asm2546076ejs.91.2023.11.18.21.40.04 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 18 Nov 2023 21:40:05 -0800 (PST) Date: Sun, 19 Nov 2023 05:40:03 +0000 (GMT) From: "Maciej W. Rozycki" To: gcc-patches@gcc.gnu.org cc: Andrew Waterman , Jim Wilson , Kito Cheng , Palmer Dabbelt Subject: [PATCH 22/44] RISC-V: Fold all the cond-move variants together In-Reply-To: Message-ID: References: User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_ASCII_DIVIDERS, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782969723333943123 X-GMAIL-MSGID: 1782969723333943123 Code in `riscv_expand_conditional_move' for Ventana and Zicond targets seems like bolted on as an afterthought rather than properly merged so as to handle all the cases together. Fold the existing code pieces together then (observing that for short forward branch targets no integer comparisons need to be canonicalized), letting T-Head targets produce branchless sequences for all the integer comparisons rather than for equality ones only, and preparing for the handling of floating-point comparisons here across all conditional-move targets. gcc/ * config/riscv/riscv.cc (riscv_expand_conditional_move): Unify conditional-move handling across all the relevant targets. --- gcc/config/riscv/riscv.cc | 58 +++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) gcc-riscv-expand-conditional-move-sfb-alu-thead.diff Index: gcc/gcc/config/riscv/riscv.cc =================================================================== --- gcc.orig/gcc/config/riscv/riscv.cc +++ gcc/gcc/config/riscv/riscv.cc @@ -4090,35 +4090,9 @@ riscv_expand_conditional_move (rtx dest, rtx_code code = GET_CODE (op); rtx op0 = XEXP (op, 0); rtx op1 = XEXP (op, 1); - bool need_eq_ne_p = false; - - if (TARGET_XTHEADCONDMOV - && GET_MODE_CLASS (mode) == MODE_INT - && (GET_MODE (op) == mode || GET_MODE (op) == E_VOIDmode) - && (GET_MODE (op0) == mode || CONST_INT_P (op0)) - && (GET_MODE (op1) == mode || CONST_INT_P (op1)) - && (code == EQ || code == NE)) - need_eq_ne_p = true; - - if (need_eq_ne_p - || (TARGET_SFB_ALU && GET_MODE (op0) == word_mode)) - { - riscv_emit_int_compare (&code, &op0, &op1, need_eq_ne_p); - rtx cond = gen_rtx_fmt_ee (code, GET_MODE (op0), op0, op1); - /* The expander is a bit loose in its specification of the true - arm of the conditional move. That allows us to support more - cases for extensions which are more general than SFB. But - does mean we need to force CONS into a register at this point. */ - cons = force_reg (mode, cons); - /* With XTheadCondMov we need to force ALT into a register too. */ - alt = force_reg (mode, alt); - emit_insn (gen_rtx_SET (dest, gen_rtx_IF_THEN_ELSE (mode, - cond, cons, alt))); - return true; - } - else if (TARGET_ZICOND_LIKE - && GET_MODE_CLASS (mode) == MODE_INT) + if ((TARGET_ZICOND_LIKE && GET_MODE_CLASS (mode) == MODE_INT) + || TARGET_SFB_ALU || TARGET_XTHEADCONDMOV) { machine_mode mode0 = GET_MODE (op0); machine_mode mode1 = GET_MODE (op1); @@ -4132,9 +4106,11 @@ riscv_expand_conditional_move (rtx dest, return false; /* Canonicalize the comparison. It must be an equality comparison - of integer operands. If it isn't, then emit an SCC instruction + of integer operands, or with SFB it can be any comparison of + integer operands. If it isn't, then emit an SCC instruction so that we can then use an equality comparison against zero. */ - if (!equality_operator (op, VOIDmode) || !INTEGRAL_MODE_P (mode0)) + if ((!TARGET_SFB_ALU && !equality_operator (op, VOIDmode)) + || !INTEGRAL_MODE_P (mode0)) { bool *invert_ptr = nullptr; bool invert = false; @@ -4166,10 +4142,26 @@ riscv_expand_conditional_move (rtx dest, op1 = XEXP (op, 1); } + if (TARGET_SFB_ALU || TARGET_XTHEADCONDMOV) + { + riscv_emit_int_compare (&code, &op0, &op1, !TARGET_SFB_ALU); + rtx cond = gen_rtx_fmt_ee (code, GET_MODE (op0), op0, op1); + + /* The expander is a bit loose in its specification of the true + arm of the conditional move. That allows us to support more + cases for extensions which are more general than SFB. But + does mean we need to force CONS into a register at this point. */ + cons = force_reg (mode, cons); + /* With XTheadCondMov we need to force ALT into a register too. */ + alt = force_reg (mode, alt); + emit_insn (gen_rtx_SET (dest, gen_rtx_IF_THEN_ELSE (mode, cond, + cons, alt))); + return true; + } /* 0, reg or 0, imm */ - if (cons == CONST0_RTX (mode) - && (REG_P (alt) - || (CONST_INT_P (alt) && alt != CONST0_RTX (mode)))) + else if (cons == CONST0_RTX (mode) + && (REG_P (alt) + || (CONST_INT_P (alt) && alt != CONST0_RTX (mode)))) { riscv_emit_int_compare (&code, &op0, &op1, true); rtx cond = gen_rtx_fmt_ee (code, GET_MODE (op0), op0, op1);