From patchwork Wed Mar 6 08:09:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 86852 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 83F263858009 for ; Wed, 6 Mar 2024 08:10:33 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id B2865385840D for ; Wed, 6 Mar 2024 08:10:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B2865385840D 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 B2865385840D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709712604; cv=none; b=RIM0K8kZr/fbuziaCGXxmYUNnozzc0lvR5TYelUfH4rmo3gob41HM2hUXv54fqSgprViDp4+9ypQfTMTFZeARIay9sjYKuzKHG5emesyqFlJqTQBBW7iAxEDLFZuRRjY9kcQWhRKShbJgyo/vUMnhk9VyoFluOhgk2kS+bB3eQk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709712604; c=relaxed/simple; bh=cBQgVW71wAIOMRPL62lEGXO1J+Twd7H13NkSX8MrEZI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=SkNwBOF+6tSjTS+aTWrPD8rCJ/+8BW1gIpra6tT9Y0o/qLgqpZYKAsf4MZfNieXHQW/p+9rmzGcrfhxktiLsIPlAz1IcjQpl1kX+ZKE+ZJM0CL2a2CMc9X3CACBcs+jPM7ggPAFcSoFSD/ej/L/qbawUWfuphlHVYp6oJjqyn34= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709712601; 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=Waxb1/SPbuXijoAdfPzpJgeZdh8aKO6Jzm9mhL20038=; b=LwZDLUIMxuy/M2O5uCiHN5s+1eXnhWLOeej/oUIpwJj3llRklsaP8NDXVJ2vPpsjlnIa9L Bquxg/SRZUuVVtoyjfZmjhks0fiZOyXEr8at2marPd4a2yCTz/qwtuSJsftwA2Wb39EPUM xyRGwqS23xrGIjktE0yvShIrUbGh934= 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-30-2D-iwth5MjOE0iUeuhuoUg-1; Wed, 06 Mar 2024 03:09:56 -0500 X-MC-Unique: 2D-iwth5MjOE0iUeuhuoUg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 0E8AE2808E65; Wed, 6 Mar 2024 08:09:56 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.226.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C5A70492BDC; Wed, 6 Mar 2024 08:09:55 +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 42689sSV3644290 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 6 Mar 2024 09:09:54 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 42689rwS3644289; Wed, 6 Mar 2024 09:09:53 +0100 Date: Wed, 6 Mar 2024 09:09:53 +0100 From: Jakub Jelinek To: Uros Bizjak , Hongtao Liu Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] i386: Fix up the vzeroupper REG_DEAD/REG_UNUSED note workaround [PR114190] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, 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+patchwork=sourceware.org@gcc.gnu.org Hi! When writing the rest_of_handle_insert_vzeroupper workaround to manually remove all the REG_DEAD/REG_UNUSED notes from the IL, I've missed that there is a df_analyze () call right after it and that the problems added earlier in the pass, like df_note_add_problem () done during mode switching, doesn't affect just the next df_analyze () call right after it, but all other df_analyze () calls until the end of the current pass where df_finish_pass removes the optional problems. So, as can be seen on the following patch, the workaround doesn't actually work there, because while rest_of_handle_insert_vzeroupper carefully removes all REG_DEAD/REG_UNUSED notes, the df_analyze () call at the end of the function immediately adds them in again (so, I must say I have no idea why the workaround worked on the earlier testcases). Now, I could move the df_analyze () call just before the REG_DEAD/REG_UNUSED note removal loop, but I think the following patch is better, because the df_analyze () call doesn't have to recompute the problem when we don't care about it and will actively strip all traces of it away. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2024-03-06 Jakub Jelinek PR rtl-optimization/114190 * config/i386/i386-features.cc (rest_of_handle_insert_vzeroupper): Call df_remove_problem for df_note before calling df_analyze. * gcc.target/i386/avx-pr114190.c: New test. Jakub --- gcc/config/i386/i386-features.cc.jj 2024-02-22 10:10:18.658032517 +0100 +++ gcc/config/i386/i386-features.cc 2024-03-05 09:23:54.496112264 +0100 @@ -2690,6 +2690,7 @@ rest_of_handle_insert_vzeroupper (void) } } + df_remove_problem (df_note); df_analyze (); return 0; } --- gcc/testsuite/gcc.target/i386/avx-pr114190.c.jj 2024-03-05 10:07:24.869454305 +0100 +++ gcc/testsuite/gcc.target/i386/avx-pr114190.c 2024-03-05 10:06:52.870889687 +0100 @@ -0,0 +1,27 @@ +/* PR rtl-optimization/114190 */ +/* { dg-do run { target avx } } */ +/* { dg-options "-O2 -fno-dce -fharden-compares -mavx --param=max-rtl-if-conversion-unpredictable-cost=136 -mno-avx512f -Wno-psabi" } */ + +#include "avx-check.h" + +typedef unsigned char U __attribute__((vector_size (64))); +typedef unsigned int V __attribute__((vector_size (64))); +U u; + +V +foo (V a, V b) +{ + u[0] = __builtin_sub_overflow (0, (int) a[0], &a[b[7] & 5]) ? -u[1] : -b[3]; + b ^= 0 != b; + return (V) u + (V) a + (V) b; +} + +static void +avx_test (void) +{ + V x = foo ((V) { 1 }, (V) { 0, 0, 0, 1 }); + if (x[0] != -1U) + __builtin_abort (); + if (x[3] != -2U) + __builtin_abort (); +}