From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1251) id 871813858D28; Sun, 18 Jun 2023 16:40:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 871813858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687106402; bh=9CyMYuF+pupBhIiqL+sF/eL0PJH0TgFmvxy+AqEu+9Y=; h=From:To:Subject:Date:From; b=dpi4R/5rNLrXEWj/WYThDzeP4jntu9UECHYK4BCFzvbGxNXalg6PhkNEDWyAhYm6Y hYgeTDURVzbIr2yQ14yX+t+uGJ4TNi3D6kwEzOCh8lur+A4LOY77JtcVgrzimfOQlA aXhgpnS6FvK/8iH5+14F+50abilPRDb1v8dVCrG4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Roger Sayle To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-1908] i386: Refactor new ix86_expand_carry to set the carry flag. X-Act-Checkin: gcc X-Git-Author: Roger Sayle X-Git-Refname: refs/heads/master X-Git-Oldrev: 55686e6601b3633a515afad1358d71c7b2d565e2 X-Git-Newrev: af29d0d6b75f9e5ad69820488972027fe4634850 Message-Id: <20230618164002.871813858D28@sourceware.org> Date: Sun, 18 Jun 2023 16:40:02 +0000 (GMT) List-Id: https://gcc.gnu.org/g:af29d0d6b75f9e5ad69820488972027fe4634850 commit r14-1908-gaf29d0d6b75f9e5ad69820488972027fe4634850 Author: Roger Sayle Date: Sun Jun 18 17:39:13 2023 +0100 i386: Refactor new ix86_expand_carry to set the carry flag. 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. 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. Diff: --- gcc/config/i386/i386-expand.cc | 24 ++++++++++++++++-------- gcc/config/i386/i386-protos.h | 1 + gcc/config/i386/i386.md | 8 ++------ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index 6a28b6767a7..98c43c6704c 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -12646,6 +12646,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). @@ -13977,14 +13992,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 af01299c130..27fe73ca65c 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 b8d2e3af02a..bfdd54f54ba 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],