From patchwork Sun Jun 18 11:10:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roger Sayle X-Patchwork-Id: 1796229 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nextmovesoftware.com header.i=@nextmovesoftware.com header.a=rsa-sha256 header.s=default header.b=qS/SBIJE; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QkVYX00ZVz20X8 for ; Sun, 18 Jun 2023 21:10:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E3D9F3857705 for ; Sun, 18 Jun 2023 11:10:13 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from server.nextmovesoftware.com (server.nextmovesoftware.com [162.254.253.69]) by sourceware.org (Postfix) with ESMTPS id 7BC173858D28 for ; Sun, 18 Jun 2023 11:10:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7BC173858D28 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=nextmovesoftware.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nextmovesoftware.com DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nextmovesoftware.com; s=default; h=Content-Type:MIME-Version:Message-ID: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=HvQYNE7jjPNYlIdFnaAbhBydKU6yO4/H+fcphD6gnHU=; b=qS/SBIJEU7DoHpT9bPrmFoIzmh Co2f0fnm9JjL1b143XqdSBdTF6sMxopYW2C4cvehJwwwGzaNoQPFIjmqN24GLjQYeoxbaJiheYbuM 9DKpyvyRcCL0vfCmLu8sDD+mrMyUaItJENr9PL++IMTlPu4jca7jZu1h+aO57axuT9DLbn/UG1BnJ +v/g4TE6186o797zzAV18OaaiAJvJHWcaNmLTIgmjRW8KkjgOeGk7FX0RxC4Hd/Xlx2LwMUBUYh6Y IekKImwBM5yyniKCdS3A4ROQHJ1957AstYDQErGN7i87FpJ5HoSk4NjrQpi4bJU9MLym0HroXmrGr YweVJkpg==; Received: from [185.62.158.67] (port=56839 helo=Dell) by server.nextmovesoftware.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1qAqIC-0002Nj-2w; Sun, 18 Jun 2023 07:10:01 -0400 From: "Roger Sayle" To: Cc: "'Uros Bizjak'" Subject: [x86 PATCH] Refactor new ix86_expand_carry to set the carry flag. Date: Sun, 18 Jun 2023 12:10:00 +0100 Message-ID: <000f01d9a1d5$6d676960$48363c20$@nextmovesoftware.com> MIME-Version: 1.0 X-Mailer: Microsoft Outlook 16.0 Thread-Index: Admh1RH+Tb2XJw/lRAGAS37sSwJNpQ== Content-Language: en-gb X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - server.nextmovesoftware.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - nextmovesoftware.com X-Get-Message-Sender-Via: server.nextmovesoftware.com: authenticated_id: roger@nextmovesoftware.com X-Authenticated-Sender: server.nextmovesoftware.com: roger@nextmovesoftware.com X-Source: X-Source-Args: X-Source-Dir: X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" This patch refactors the three places in the i386.md backend that we set the carry flag into a new ix86_expand_carry helper function, that allows Jakub's recently added uaddc5 and usubc5 expanders to take advantage of the recently added support for the stc instruction. This patch has been tested on x86_64-pc-linux-gnu with make bootstrap and make -k check, both with and without --target_board=unix{-m32} with no new failures. Ok for mainline? 2023-06-18 Roger Sayle gcc/ChangeLog * config/i386/i386-expand.cc (ix86_expand_carry): New helper function for setting the carry flag. (ix86_expand_builtin) : Use it here. * config/i386/i386-protos.h (ix86_expand_carry): Prototype here. * config/i386/i386.md (uaddc5): Use ix86_expand_carry. (usubc5): Likewise. Thanks in advance, Roger diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index def060a..3d5eca6 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -12644,6 +12644,21 @@ ix86_check_builtin_isa_match (unsigned int fcode, return (bisa & isa) == bisa && (bisa2 & isa2) == bisa2; } +/* Emit instructions to set the carry flag from ARG. */ + +void +ix86_expand_carry (rtx arg) +{ + if (!CONST_INT_P (arg) || arg == const0_rtx) + { + arg = convert_to_mode (QImode, arg, 1); + arg = copy_to_mode_reg (QImode, arg); + emit_insn (gen_addqi3_cconly_overflow (arg, constm1_rtx)); + } + else + emit_insn (gen_x86_stc ()); +} + /* Expand an expression EXP that calls a built-in function, with result going to TARGET if that's convenient (and in mode MODE if that's convenient). @@ -13975,14 +13990,7 @@ rdseed_step: else { /* Generate CF from input operand. */ - if (!CONST_INT_P (op1)) - { - op1 = convert_to_mode (QImode, op1, 1); - op1 = copy_to_mode_reg (QImode, op1); - emit_insn (gen_addqi3_cconly_overflow (op1, constm1_rtx)); - } - else - emit_insn (gen_x86_stc ()); + ix86_expand_carry (op1); /* Generate instruction that consumes CF. */ op1 = gen_rtx_REG (CCCmode, FLAGS_REG); diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h index af01299..27fe73c 100644 --- a/gcc/config/i386/i386-protos.h +++ b/gcc/config/i386/i386-protos.h @@ -155,6 +155,7 @@ extern void ix86_expand_sse_movcc (rtx, rtx, rtx, rtx); extern void ix86_expand_sse_unpack (rtx, rtx, bool, bool); extern void ix86_expand_fp_spaceship (rtx, rtx, rtx); extern bool ix86_expand_int_addcc (rtx[]); +extern void ix86_expand_carry (rtx arg); extern rtx_insn *ix86_expand_call (rtx, rtx, rtx, rtx, rtx, bool); extern bool ix86_call_use_plt_p (rtx); extern void ix86_split_call_vzeroupper (rtx, rtx); diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 93794c1..a50cbc8 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -8601,9 +8601,7 @@ emit_insn (gen_addcarry_0 (operands[0], operands[2], operands[3])); else { - rtx op4 = copy_to_mode_reg (QImode, - convert_to_mode (QImode, operands[4], 1)); - emit_insn (gen_addqi3_cconly_overflow (op4, constm1_rtx)); + ix86_expand_carry (operands[4]); pat = gen_rtx_LTU (mode, cf, const0_rtx); pat2 = gen_rtx_LTU (mode, cf, const0_rtx); emit_insn (gen_addcarry (operands[0], operands[2], operands[3], @@ -8634,9 +8632,7 @@ else { cf = gen_rtx_REG (CCCmode, FLAGS_REG); - rtx op4 = copy_to_mode_reg (QImode, - convert_to_mode (QImode, operands[4], 1)); - emit_insn (gen_addqi3_cconly_overflow (op4, constm1_rtx)); + ix86_expand_carry (operands[4]); pat = gen_rtx_LTU (mode, cf, const0_rtx); pat2 = gen_rtx_LTU (mode, cf, const0_rtx); emit_insn (gen_subborrow (operands[0], operands[2], operands[3],