From patchwork Tue Dec 5 22:23:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1872337 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aHrUv4n7; 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 4SlFRz0SyYz1ySd for ; Wed, 6 Dec 2023 09:23:42 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CD68D3858D37 for ; Tue, 5 Dec 2023 22:23:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 4516F3858D37 for ; Tue, 5 Dec 2023 22:23:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4516F3858D37 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4516F3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701815009; cv=none; b=MuGXGd9OcGhn7DbEHctTY4VmQeiATyKvFGOElYitSsps42tqHE2I+4UdpPbyu0O1S9vKRsONzaggo6Sbpu90+Nsz5cXqFFby7ZlYoRkUeWFsNtKj0FnjWSSNk0LrgQikVByh+nVDZ6zGLMOiMCgpaH9R8BP8dyCJxEwYm+HgYVI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701815009; c=relaxed/simple; bh=sf9Kk2QAiwd+XSAFFi51OpdBjfCU3vdl+AMlMYoYoQQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=qmxX5K/2mY4ir1mcuU1hVsOi+S1SqULFfg//EpOYyQnySeGAwHgfeZUzbg5fkJvOlq6Z9crVCKAAbN1wbInx5/Eed3P0xwyzh57Kg7VNsrpsEID7Uy2P49Zo5+9PkS7bPHd8wWmFtr3Pg0EDLCH9+K+apwksTg5z6+xF/obrgZQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701815007; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=oznBCnb5+hAB/nwmKOTXVVGt3Wwb58oK0cnaW5+wZq4=; b=aHrUv4n7mxYIZTYAk85KEGZmSTiTuMG63SVTG1EZg5HZydmS5P3VLVAIHRsXo/INWWzY7u Eg3T2l+FO/I6FRhdW4iQi+B3R3A5ceNT5uz0suHr6iTlwk+7NHb4YrsDm+QIN4uD8Vg7uP Jd+CiI9xjZ1khXaYLUfIKyxksbXxcTk= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-391-xFIgSab0O4Sry7zG2kx3Aw-1; Tue, 05 Dec 2023 17:23:24 -0500 X-MC-Unique: xFIgSab0O4Sry7zG2kx3Aw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 260A7380627A; Tue, 5 Dec 2023 22:23:24 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.195.157]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC83F40C6EB9; Tue, 5 Dec 2023 22:23:23 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3B5MNLMD1483449 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 5 Dec 2023 23:23:21 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3B5MNK2D1483448; Tue, 5 Dec 2023 23:23:20 +0100 Date: Tue, 5 Dec 2023 23:23:20 +0100 From: Jakub Jelinek To: Uros Bizjak , Hongtao Liu Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: Move vzeroupper pass from after reload pass to after postreload_cse [PR112760] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Hi! Regardless of the outcome of the REG_UNUSED discussions, I think it is a good idea to move the vzeroupper pass one pass later. As can be seen in the multiple PRs and as postreload.cc documents, reload/LRA is known to create dead statements quite often, which is the reason why we have postreload_cse pass at all. Doing vzeroupper pass before such cleanup means the pass including df_analyze for it needs to process more instructions than needed and because mode switching adds note problem, also higher chance of having stale REG_UNUSED notes. And, I really don't see why vzeroupper can't wait until those cleanups are done. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-12-05 Jakub Jelinek PR rtl-optimization/112760 * config/i386/i386-passes.def (pass_insert_vzeroupper): Insert after pass_postreload_cse rather than pass_reload. * config/i386/i386-features.cc (rest_of_handle_insert_vzeroupper): Adjust comment for it. * gcc.dg/pr112760.c: New test. Jakub --- gcc/config/i386/i386-passes.def.jj 2023-01-16 11:52:15.960735877 +0100 +++ gcc/config/i386/i386-passes.def 2023-12-05 19:15:01.748279329 +0100 @@ -24,7 +24,7 @@ along with GCC; see the file COPYING3. REPLACE_PASS (PASS, INSTANCE, TGT_PASS) */ - INSERT_PASS_AFTER (pass_reload, 1, pass_insert_vzeroupper); + INSERT_PASS_AFTER (pass_postreload_cse, 1, pass_insert_vzeroupper); INSERT_PASS_AFTER (pass_combine, 1, pass_stv, false /* timode_p */); /* Run the 64-bit STV pass before the CSE pass so that CONST0_RTX and CONSTM1_RTX generated by the STV pass can be CSEed. */ --- gcc/config/i386/i386-features.cc.jj 2023-11-02 07:49:15.029894060 +0100 +++ gcc/config/i386/i386-features.cc 2023-12-05 19:15:48.658620698 +0100 @@ -2627,10 +2627,11 @@ convert_scalars_to_vector (bool timode_p static unsigned int rest_of_handle_insert_vzeroupper (void) { - /* vzeroupper instructions are inserted immediately after reload to - account for possible spills from 256bit or 512bit registers. The pass - reuses mode switching infrastructure by re-running mode insertion - pass, so disable entities that have already been processed. */ + /* vzeroupper instructions are inserted immediately after reload and + postreload_cse to clean up after it a little bit to account for possible + spills from 256bit or 512bit registers. The pass reuses mode switching + infrastructure by re-running mode insertion pass, so disable entities + that have already been processed. */ for (int i = 0; i < MAX_386_ENTITIES; i++) ix86_optimize_mode_switching[i] = 0; --- gcc/testsuite/gcc.dg/pr112760.c.jj 2023-12-01 13:46:57.444746529 +0100 +++ gcc/testsuite/gcc.dg/pr112760.c 2023-12-01 13:46:36.729036971 +0100 @@ -0,0 +1,22 @@ +/* PR rtl-optimization/112760 */ +/* { dg-do run } */ +/* { dg-options "-O2 -fno-dce -fno-guess-branch-probability --param=max-cse-insns=0" } */ +/* { dg-additional-options "-m8bit-idiv -mavx" { target i?86-*-* x86_64-*-* } } */ + +unsigned g; + +__attribute__((__noipa__)) unsigned short +foo (unsigned short a, unsigned short b) +{ + unsigned short x = __builtin_add_overflow_p (a, g, (unsigned short) 0); + g -= g / b; + return x; +} + +int +main () +{ + unsigned short x = foo (40, 6); + if (x != 0) + __builtin_abort (); +}