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: 109599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2402838vqr; Sun, 18 Jun 2023 04:10:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ahYf+0EQyeG/0CylVdBPdf/h7t8cZYe9srWKJowoYR/ZUiU3Fo1qtOE0W00PRig9Luq0R X-Received: by 2002:a05:6402:2cd:b0:514:3e1:239c with SMTP id b13-20020a05640202cd00b0051403e1239cmr4283597edx.42.1687086634075; Sun, 18 Jun 2023 04:10:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687086634; cv=none; d=google.com; s=arc-20160816; b=ZvaMDVONGZp42Uu5zXFGrQqgkgeinJG3+UPYagnlUwwGaaz3mGVkRECJMUNuWj4ht0 ZK10uijsNNlVKW05O+h5lnqTL4R3wc78VUe914NVAu0nnkSqwudIsT3dqLRhvuAkyJ/t M8nXNkG135JgZU1RjxD9gO5nfnahu4F9GFlEPNVmY5NqDUYVeUvhsmpTgayPAYHOZUso s1i02LKLjD4IoOYOQr8HPrHBbot4hog+Mau4JeJqHsnJfS9QZFJ9X085Q51LWmGTVQ7Q qJWMbGpAANyufZmzX+bpVSoqzJCD+g2gNIhCzWFyuCS8MAiYr4wrJoXJ2LAWisKB6i0M qmng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-language:thread-index :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=HvQYNE7jjPNYlIdFnaAbhBydKU6yO4/H+fcphD6gnHU=; b=sLh67riatvUIIbtATRV0fH+ub3mhWCHp5629h1JlxFjPUcMD1JL8hOuWVw/E/OlkXH U+efHnFBW4kmpVIe78/vdWE9VXFCGWcx6WsgEXe/M+sRE5zevCc2S8f8ITVIPiv7jCit qPtsvbQzWxOooYG/LBi8QLGsX5jdEYgdKghcGNDCx5f64IF4xnd3NrKXkNyozlHRZVeD 5ew62g6HPYn8ikLxHT/jzTqgoEVGiyrxTxyJlJZ24A+WuFPjwL2XXoMHW56h8JEWXuS2 CoDXcaVzgZrfub8MjqM02DmBKnZpaJwi0erf4gXceDPiAAyT2Hn9DzEM9djBiFsAD7nR YQfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nextmovesoftware.com header.s=default header.b="qS/SBIJE"; 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 sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id r10-20020aa7cb8a000000b005149e0f8897si12715176edt.331.2023.06.18.04.10.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jun 2023 04:10:34 -0700 (PDT) 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=fail header.i=@nextmovesoftware.com header.s=default header.b="qS/SBIJE"; 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 894713858284 for ; Sun, 18 Jun 2023 11:10:26 +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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769038554589549008?= X-GMAIL-MSGID: =?utf-8?q?1769038554589549008?= 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],