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: 174222 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3741407vqy; Tue, 5 Dec 2023 14:23:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5zLcpVokEFNhekfU4tOS1Dt/XNerXLgTOERIVdRMGmwWUsGYVLWhSEeqAQnepLpN0pl4F X-Received: by 2002:a81:7357:0:b0:5bf:f4b7:4a77 with SMTP id o84-20020a817357000000b005bff4b74a77mr5785412ywc.47.1701815033177; Tue, 05 Dec 2023 14:23:53 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701815033; cv=pass; d=google.com; s=arc-20160816; b=qb70EA+t/H4jyCuhYCm3Qo3av8+hobKfXcW2doHsGUPctmVvre9RTd/Rii15sS8nG5 PToeEa68eMbXmdUITAFdKKsSCTrHaFyswieIHUCVde83h5xf7bhkXUVyPpDkUYe/hSHF 0mbIslDHEVGiSjFtg9E6kLGVIdKzT9RKIj8LGfE7xL48Pe0G7kf3DuZzPJM3Y7NZW6Ld eR1GrvGQA58sn3ZkVSAl5tRJ9Nz7GwdfScDv2ypyVTefeholT4I9DbvOxXxHYB8KPBkS 2yH4u4fFX/gd4qE0f9aA/ZwsgcSytDhAR1WJv5zKsfG+wUs6uzFjaJWWGiknjo0Qd6hM TaTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=oznBCnb5+hAB/nwmKOTXVVGt3Wwb58oK0cnaW5+wZq4=; fh=dJXZiVMspIcJXx0uc9+L7YPq9u8lPiw3EGoQOJFZpWA=; b=YtiXL9yz6SCCWFqvy0IcmCJ2syhV+8d5q62G0F6SdKiwJir9tNixO9vEJKTJ69OlsB o4TFXKJIm2DZ6JftbCPiExyjwwIu83KOpu6I5aylo2CNISQ2KqPVovYAKYhGDO44fhTw QkhCQPSbfQadXTwn1Krawvvbz0fmI2K4baMpty80JOUVkyi8b1QirrP7tVYW49q5rBFo I2pNJJxWpZ0Qtvt9tIIPyTKiCaoylhiW27Bj8b45ItM6BSep5UUKxr2wyJ+3XQxaxpyR MKJl/lswS482CsKRfdm0FzqPOmntdvT/2ILfBJOSKvVFZRMF3pDXKANjtLPKlELsE8tg eKUg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aHrUv4n7; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id fq11-20020a056214258b00b0067aa11dedf1si10834783qvb.333.2023.12.05.14.23.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 14:23:53 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=aHrUv4n7; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E57AB385B537 for ; Tue, 5 Dec 2023 22:23:52 +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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784482399998935424 X-GMAIL-MSGID: 1784482399998935424 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 (); +}