From patchwork Mon Nov 13 22:57:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uros Bizjak X-Patchwork-Id: 1863396 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=bt9SWpx6; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4STlFl3y5vz1yRG for ; Tue, 14 Nov 2023 09:58:02 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C9A0A3831E08 for ; Mon, 13 Nov 2023 22:57:59 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 087B03858415 for ; Mon, 13 Nov 2023 22:57:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 087B03858415 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 087B03858415 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699916267; cv=none; b=tAjuinaDvJZ0i/9NH2w5uvpjNLKByfwPLJvhW17yde5UL9oK30rT4ALLZYgrP2KgtdEe6nDNBHAGLhmRlab0Qqpa9qej+U0Udb2KPSTLDLTrwNRmAUuze9lkAjyOCEUv74RADMdVvCktkCb7Q+PHgq4Wj+P8zM6X1q7BVhdiitE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699916267; c=relaxed/simple; bh=lpg/qX6syEiSmHEs5dwVAeWGScgvVHkHVCxHHJxsC9M=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=SiGlMWCQ8ER7Si5069o6cNAF3fHQHZnI2mzm6WEtIUvzdb39hqld1RvssnW+rOYrloqGtCYDgq3+1pr0T9WVYuwPPHjAOCjChjpkpu5qvGNz6jO5bcKfLssiELogNeSe7hfSUmiZLlVQq08G3G2JMMSG5kiSdPD0ofSjuR0yfa4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4083740f92dso40608505e9.3 for ; Mon, 13 Nov 2023 14:57:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699916264; x=1700521064; darn=gcc.gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=yOSgUfZAVaoX0MIdvljrXPeBUBvntWHVNDLkH3ACr1I=; b=bt9SWpx6UyQy483+BFeWt2+qROx33pMYuXa2O/0J89WrJIESwDwO5AA3sEExNSnYgy 2t2JXLFwDMbVXTJBpqEXVmdJfhaqcIpmOGY3pF1e8s6odRvV4C54aGjhW6/hDc6ZoYGE y98i65chAamN6ZCfCZkdJmPJxjCJVkuQqaZzz/dZ8nvBSKT4NjE2s6+QtAkjlQFgmSbu 0IsKcK+PG1XPhk0VTgbWOxXQKXCFobLRhGh1w+l7KNRz3265bkvmOTVOp+4J7sKOqs+9 trCMBLv5PSuKNZ5H2IJhv7fa2cinV7WUg8a5fvzInKyP1OXdELatLAC0ecsjOYVoenh/ MKFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699916264; x=1700521064; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yOSgUfZAVaoX0MIdvljrXPeBUBvntWHVNDLkH3ACr1I=; b=TN/SX6++QdlUk2b6FG9f6jP7o56ingfl81gJVLrfi4ACa/ZG8ZCNP1ZqEGB9rVvqyQ KR8Cdvm+upGIh6ye6+DG3GKwgIeN55h2VUBdW605VqUiFhfk6jloINqD/t6GU6RGZLTw GHjXVXmiTd/F2FSiNwhLBjwEgItFRL3EbGvi4JG8S2AkX37aYKZ2sJxScfpzJbFkwy0d s2Hc9ZEAiLr65kPYv6R1EUjRCVzHJ3oaIV9pEh0/cEd8VmDYoT2DPP7M1jc0q/ofEMrn R7op1l30wFZnzyv0wW19KVTtmNl4c4hFXrMhWiII9yFk9GmgIT7WuwiKEAteMnmX1032 CJ0A== X-Gm-Message-State: AOJu0Ywu2FVtkeWucXqpgvFxidDtImcWYnnQ6QNqPOo3N0PdminVUDsD PkDEFxXfJXTDZKlDs4vH74lNypLh9aeBBBWHYk2YC2+ozzSSEw== X-Google-Smtp-Source: AGHT+IHOONEJridpyqCv+HMaD4fGt51K/VfirNTCLCrQvy9EGw3oe5eSN7zEXbsMBOCkXoDZMcE7d1bqJUBUkG6OXWM= X-Received: by 2002:a5d:6b86:0:b0:32f:7f17:b049 with SMTP id n6-20020a5d6b86000000b0032f7f17b049mr4947122wrx.39.1699916264348; Mon, 13 Nov 2023 14:57:44 -0800 (PST) MIME-Version: 1.0 From: Uros Bizjak Date: Mon, 13 Nov 2023 23:57:33 +0100 Message-ID: Subject: [committed] i386: Rewrite pushfl2 and popfl1 as unspecs To: "gcc-patches@gcc.gnu.org" X-Spam-Status: No, score=-8.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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.30 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 Flags reg is valid only with CC mode. gcc/ChangeLog: * config/i386/i386-expand.h (gen_pushfl): New prototype. (gen_popfl): Ditto. * config/i386/i386-expand.cc (ix86_expand_builtin) [case IX86_BUILTIN_READ_FLAGS]: Use gen_pushfl. [case IX86_BUILTIN_WRITE_FLAGS]: Use gen_popfl. * config/i386/i386.cc (gen_pushfl): New function. (gen_popfl): Ditto. * config/i386/i386.md (unspec): Add UNSPEC_PUSHFL and UNSPEC_POPFL. (@pushfl2): Rename from *pushfl2. Rewrite as unspec using UNSPEC_PUSHFL. (@popfl1): Rename from *popfl1. Rewrite as unspec using UNSPEC_POPFL. Bootstrapped and regression tested on x86_64-linux-gnu {,-m32}. Uros. diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index b52ec51fbe4..a8d871d321e 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -14265,7 +14265,7 @@ rdseed_step: if (ignore) return const0_rtx; - emit_insn (gen_push (gen_rtx_REG (word_mode, FLAGS_REG))); + emit_insn (gen_pushfl ()); if (optimize || target == NULL_RTX @@ -14284,7 +14284,7 @@ rdseed_step: op0 = copy_to_mode_reg (word_mode, op0); emit_insn (gen_push (op0)); - emit_insn (gen_pop (gen_rtx_REG (word_mode, FLAGS_REG))); + emit_insn (gen_popfl ()); return 0; case IX86_BUILTIN_KTESTC8: diff --git a/gcc/config/i386/i386-expand.h b/gcc/config/i386/i386-expand.h index 8e65f7dee45..1ea789c4c3a 100644 --- a/gcc/config/i386/i386-expand.h +++ b/gcc/config/i386/i386-expand.h @@ -45,7 +45,9 @@ enum calling_abi ix86_function_abi (const_tree fndecl); bool ix86_function_ms_hook_prologue (const_tree fn); void warn_once_call_ms2sysv_xlogues (const char *feature); rtx gen_push (rtx arg); +rtx gen_pushfl (void); rtx gen_pop (rtx arg); +rtx gen_popfl (void); rtx ix86_expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode, int ignore); bool ix86_vectorize_vec_perm_const (machine_mode vmode, machine_mode op_mode, diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 176ca650aa2..683ac643bc8 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -6465,6 +6465,24 @@ gen_push (rtx arg) arg); } +rtx +gen_pushfl (void) +{ + struct machine_function *m = cfun->machine; + rtx flags, mem; + + if (m->fs.cfa_reg == stack_pointer_rtx) + m->fs.cfa_offset += UNITS_PER_WORD; + m->fs.sp_offset += UNITS_PER_WORD; + + flags = gen_rtx_REG (CCmode, FLAGS_REG); + + mem = gen_rtx_MEM (word_mode, + gen_rtx_PRE_DEC (Pmode, stack_pointer_rtx)); + + return gen_pushfl2 (word_mode, mem, flags); +} + /* Generate an "pop" pattern for input ARG. */ rtx @@ -6479,6 +6497,19 @@ gen_pop (rtx arg) stack_pointer_rtx))); } +rtx +gen_popfl (void) +{ + rtx flags, mem; + + flags = gen_rtx_REG (CCmode, FLAGS_REG); + + mem = gen_rtx_MEM (word_mode, + gen_rtx_POST_INC (Pmode, stack_pointer_rtx)); + + return gen_popfl1 (word_mode, flags, mem); +} + /* Generate a "push2" pattern for input ARG. */ rtx gen_push2 (rtx mem, rtx reg1, rtx reg2) diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 47d21f12c5b..29289f48e9c 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -115,6 +115,8 @@ (define_c_enum "unspec" [ UNSPEC_SBB UNSPEC_CC_NE UNSPEC_STC + UNSPEC_PUSHFL + UNSPEC_POPFL ;; For SSE/MMX support: UNSPEC_FIX_NOTRUNC @@ -2205,17 +2207,19 @@ (define_insn "*pop1_epilogue" [(set_attr "type" "pop") (set_attr "mode" "")]) -(define_insn "*pushfl2" +(define_insn "@pushfl2" [(set (match_operand:W 0 "push_operand" "=<") - (match_operand:W 1 "flags_reg_operand"))] + (unspec:W [(match_operand:CC 1 "flags_reg_operand")] + UNSPEC_PUSHFL))] "" "pushf{}" [(set_attr "type" "push") (set_attr "mode" "")]) -(define_insn "*popfl1" - [(set (match_operand:W 0 "flags_reg_operand") - (match_operand:W 1 "pop_operand" ">"))] +(define_insn "@popfl1" + [(set (match_operand:CC 0 "flags_reg_operand") + (unspec:CC [(match_operand:W 1 "pop_operand" ">")] + UNSPEC_POPFL))] "" "popf{}" [(set_attr "type" "pop")