From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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-Google-Smtp-Source: AGHT+IEB1DXW+P3QnvaAqvQ7q3xLStlj/xHIAQ7Qz7ng4tOAojp2PUdMesw7urp9S4A3GI3rFVRN1w== 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 Content-Type: text/plain; charset=US-ASCII 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 List-Id: 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);