From patchwork Thu Sep 7 14:06:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Makarov X-Patchwork-Id: 1830943 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=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=LyYSxewT; 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 4RhLdz5wXRz1ygc for ; Fri, 8 Sep 2023 00:07:03 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C32243857715 for ; Thu, 7 Sep 2023 14:07:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C32243857715 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1694095621; bh=dhc/eGkD9EpH4JuxjEPP4wnuZuaupQ9krHd7JVUtfBI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=LyYSxewTv6oXnJnTXOVLA4YB5LFSNW2dU8zIt4T7BCHFWywVR8fmYVo7ygy8GEvFo 7h/Yv5iSrAsK82oBNlnEenh+XzVQaz7084A1+ME4tXd8EBEbyYjLcpMuHEcx0dUKwn 2pBkqgsaCbVA5oDeAOsFisIVZdBhZeWIhepKND2o= 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 61D753858410 for ; Thu, 7 Sep 2023 14:06:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61D753858410 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-150-Zvv8oMYpMNypiQXPbX7AvQ-1; Thu, 07 Sep 2023 10:06:22 -0400 X-MC-Unique: Zvv8oMYpMNypiQXPbX7AvQ-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-76f29f14e0aso103147185a.0 for ; Thu, 07 Sep 2023 07:06:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1694095581; x=1694700381; h=subject:from:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zd5yOOC7gqCE343pJGX9wVBxdPCFUgN07gbC3yz55aM=; b=T9FDynll1M3+ZbgRan8h3nmt7InFu/4YBdXecEHiJE1VH2LgAfn8KMGpWH8rqIYLA/ MnBBglSyKUWJUzaNl0DPoQkNHSGNPzYt0fB8p5mhN4ZDZiMwb4LbdimQNSEuE6VwdBGL gVngkX3uEMjsj8m9rPackuRpWoKsvTwabDdu10V0iE+UtEhlvtJAE9iEpuKtQdSKNuN5 QyR1Ich2LJXJJxmbATR2Tq0W+Dj0bS/3DX5I9risA/FcCgIZ/6GzPAukPk+jwB/cVz2D IOF2X5ur33RCto3hPRekZ4vatM9+lpyrWrn12MV89Vp2sDXwXOFCDbs8s3kH5JtBQB3m w1EQ== X-Gm-Message-State: AOJu0Yz30hztan+Ngfj51jBIZyANRBpd9EMIf83UiLSUgzwLfNhYVdtk 9FS8Yi2p1d1WPN1sXj1OFmWrLO8XCdX5GbAe9CZw1dcu15ECb8q93rE2m3WTEIkiALhL0qN0PZM ADI7kcuI4T53s6hG9E6k8AljZ60lyoUpQy9JejXuHoMY2PiRUJhnHndL4nJu1+6ZTqyzSbZ6p8O wxGPG4 X-Received: by 2002:a05:620a:2ae2:b0:76e:eeaa:a06e with SMTP id bn34-20020a05620a2ae200b0076eeeaaa06emr20003174qkb.4.1694095581795; Thu, 07 Sep 2023 07:06:21 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFK+KPuma5KKY0mxPr8mgT6C3uR0FYgxYfXKukbmW4Il8z3xMjSUkMYdEzH5WimzJGk7tZrwQ== X-Received: by 2002:a05:620a:2ae2:b0:76e:eeaa:a06e with SMTP id bn34-20020a05620a2ae200b0076eeeaaa06emr20003147qkb.4.1694095581476; Thu, 07 Sep 2023 07:06:21 -0700 (PDT) Received: from [192.168.1.88] (192-0-143-139.cpe.teksavvy.com. [192.0.143.139]) by smtp.gmail.com with ESMTPSA id j15-20020a0cc34f000000b00655935bca82sm2201402qvi.134.2023.09.07.07.06.20 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Sep 2023 07:06:21 -0700 (PDT) Message-ID: Date: Thu, 7 Sep 2023 10:06:20 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 To: "gcc-patches@gcc.gnu.org" Subject: [pushed][PR111225][LRA]: Don't reuse chosen insn alternative with special memory constraint X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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: , X-Patchwork-Original-From: Vladimir Makarov via Gcc-patches From: Vladimir Makarov Reply-To: Vladimir Makarov Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The following patch solves https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111225 The patch was successfully bootstrapped and tested on x86-64, aarch64, and ppc64le. commit f7bca44d97ad01b39f9d6e7809df7bf517eeb2fb Author: Vladimir N. Makarov Date: Thu Sep 7 09:59:10 2023 -0400 [LRA]: Don't reuse chosen insn alternative with special memory constraint To speed up GCC, LRA reuses chosen alternative from previous constraint subpass. A spilled pseudo is considered ok for any memory constraint although stack slot assigned to the pseudo later might not satisfy the chosen alternative constraint. As we don't consider all insn alternatives on the subsequent LRA sub-passes, it might result in LRA failure to generate the correct insn. This patch solves the problem. gcc/ChangeLog: PR target/111225 * lra-constraints.cc (goal_reuse_alt_p): New global flag. (process_alt_operands): Set up the flag. Clear flag for chosen alternative with special memory constraints. (process_alt_operands): Set up used insn alternative depending on the flag. gcc/testsuite/ChangeLog: PR target/111225 * gcc.target/i386/pr111225.c: New test. diff --git a/gcc/lra-constraints.cc b/gcc/lra-constraints.cc index c718bedff32..3aaa4906999 100644 --- a/gcc/lra-constraints.cc +++ b/gcc/lra-constraints.cc @@ -1462,6 +1462,9 @@ static int goal_alt_matches[MAX_RECOG_OPERANDS]; static int goal_alt_dont_inherit_ops_num; /* Numbers of operands whose reload pseudos should not be inherited. */ static int goal_alt_dont_inherit_ops[MAX_RECOG_OPERANDS]; +/* True if we should try only this alternative for the next constraint sub-pass + to speed up the sub-pass. */ +static bool goal_reuse_alt_p; /* True if the insn commutative operands should be swapped. */ static bool goal_alt_swapped; /* The chosen insn alternative. */ @@ -2130,6 +2133,7 @@ process_alt_operands (int only_alternative) int curr_alt_dont_inherit_ops_num; /* Numbers of operands whose reload pseudos should not be inherited. */ int curr_alt_dont_inherit_ops[MAX_RECOG_OPERANDS]; + bool curr_reuse_alt_p; /* True if output stack pointer reload should be generated for the current alternative. */ bool curr_alt_out_sp_reload_p; @@ -2217,6 +2221,7 @@ process_alt_operands (int only_alternative) reject += static_reject; early_clobbered_regs_num = 0; curr_alt_out_sp_reload_p = false; + curr_reuse_alt_p = true; for (nop = 0; nop < n_operands; nop++) { @@ -2574,7 +2579,10 @@ process_alt_operands (int only_alternative) if (satisfies_memory_constraint_p (op, cn)) win = true; else if (spilled_pseudo_p (op)) - win = true; + { + curr_reuse_alt_p = false; + win = true; + } break; } break; @@ -3318,6 +3326,7 @@ process_alt_operands (int only_alternative) goal_alt_offmemok[nop] = curr_alt_offmemok[nop]; } goal_alt_dont_inherit_ops_num = curr_alt_dont_inherit_ops_num; + goal_reuse_alt_p = curr_reuse_alt_p; for (nop = 0; nop < curr_alt_dont_inherit_ops_num; nop++) goal_alt_dont_inherit_ops[nop] = curr_alt_dont_inherit_ops[nop]; goal_alt_swapped = curr_swapped; @@ -4399,7 +4408,8 @@ curr_insn_transform (bool check_only_p) } lra_assert (goal_alt_number >= 0); - lra_set_used_insn_alternative (curr_insn, goal_alt_number); + lra_set_used_insn_alternative (curr_insn, goal_reuse_alt_p + ? goal_alt_number : LRA_UNKNOWN_ALT); if (lra_dump_file != NULL) { diff --git a/gcc/testsuite/gcc.target/i386/pr111225.c b/gcc/testsuite/gcc.target/i386/pr111225.c new file mode 100644 index 00000000000..5d92daf215b --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr111225.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fsanitize=thread -mforce-drap -mavx512cd" } */ + +typedef long long __m256i __attribute__ ((__vector_size__ (32))); + +int foo (__m256i x, __m256i y) +{ + __m256i a = x & ~y; + return !__builtin_ia32_ptestz256 (a, a); +} + +int bar (__m256i x, __m256i y) +{ + __m256i a = ~x & y; + return !__builtin_ia32_ptestz256 (a, a); +}