From patchwork Wed Sep 1 23:17:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jeff Law X-Patchwork-Id: 1523434 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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=YA65QW9F; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4H0KjV2RtCz9sVw for ; Thu, 2 Sep 2021 09:18:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 46643385B83E for ; Wed, 1 Sep 2021 23:18:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 46643385B83E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1630538282; bh=FnJVZ0rwhtrJ/1EQzqjkL2zKiT5PIrrsgB6VFof4gFs=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=YA65QW9FFJS06czklSZ4D6A3XjExFsWUKFDIpiE+9cq7zQ7iHM+jIklCe6EQ4ttC1 4ld/MJzqk7iNf05ViH3En6lT5BOiCCYdZURcoxlP+VcVw+qxFmvpWtTjFgmrBNqMsu 3zg6qk7n6/z1Iu/tNA22ECioHr8eqEpu1MfmzXWc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id 55E3A3858412 for ; Wed, 1 Sep 2021 23:17:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 55E3A3858412 Received: by mail-pf1-x433.google.com with SMTP id x16so158586pfh.2 for ; Wed, 01 Sep 2021 16:17:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-language; bh=FnJVZ0rwhtrJ/1EQzqjkL2zKiT5PIrrsgB6VFof4gFs=; b=jDirtozf4mue6uelOwt8/ezhIbzjClEqXgXVMr+8MjnpIQeriypsod+zVFMuuy2Sqb GXmS6sAokaQNY0mhTvqEv/vGnjfjK/vNzxLPb2qtDoEqsACE/XKhSMrym89lE02ZnF8R a2wXMijRLckYR0fLschPRaYUM40F4OtP7lHxr/dlTHmXLORpDT7kzQe5CgNKzBFBajOX 89o06DegiHt/YpalkAqoWD+UdAiJBACW8IV056j/ULB4uUW7AmMSc2ElySNCAYnYy2Ju t+7wAcKKM/qPEKqIfRL8kKnP2FvA9HFNJf/VmkaXNqWAIYEcmHOTh8aEpRvo3UKAKIgm Ql4Q== X-Gm-Message-State: AOAM530k8SB2bcUBe0D6VcfYrVd0/YuvqQH9xlYoXhlhGP6YQhIL8gSy WgsKCw+58v8vYV0a+tWFxamQFMpjKJg= X-Google-Smtp-Source: ABdhPJz9Kt7OOPqSGXZrJDtd7YZLSBfb+tnHp0ZQ66CnXbIcVgIK0+FcKaiZ2VX8liOdUpo1ZtxWOg== X-Received: by 2002:a62:e416:0:b0:409:4e86:5253 with SMTP id r22-20020a62e416000000b004094e865253mr280871pfh.76.1630538258099; Wed, 01 Sep 2021 16:17:38 -0700 (PDT) Received: from [192.168.1.24] (65-130-15-252.slkc.qwest.net. [65.130.15.252]) by smtp.gmail.com with ESMTPSA id t15sm18060pgk.13.2021.09.01.16.17.37 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Sep 2021 16:17:37 -0700 (PDT) Subject: [committed] [PR tree-optimization/102152] Call reduce_vector_comparison_to_scalar_comparison earlier To: GCC Patches Message-ID: Date: Wed, 1 Sep 2021 17:17:36 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 Content-Language: en-US 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 autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jeff Law via Gcc-patches From: Jeff Law Reply-To: Jeff Law Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" As noted in the PR, we can get an ICE after the introduction of code to reduce a vector comparison to a scalar.  The problem is we left the operand cache in an inconsistent state because we called the new function too late. This is trivially fixed by making the transformation before we call update_stmt_if_modified. The irony here is the whole point of calling reduce_vector_comparison_to_scalar_comparison when we did was to expose these kinds of secondary opportunities.  In this particular case we collapsed the test to a comparison of constants (thus no SSA operands). Anyway, this fixes the problem in the obvious way.  This may all end up being moot if I can twiddle Richi's match.pd pattern to work.  It doesn't work as-written due to a couple issues that I haven't worked totally through yet.  It seemed better to get the regression fixed immediately rather than wait for the match.pd work. Installed on the trunk after bootstrap & regression testing on x86 and verifying it addresses the aarch64 issue. Jeff commit 165446a1e81f5bb9597289e783af9ee67e1fe5ba Author: Jeff Law Date: Wed Sep 1 19:13:58 2021 -0400 Call reduce_vector_comparison_to_scalar_comparison earlier As noted in the PR, we can get an ICE after the introduction of code to reduce a vector comparison to a scalar. The problem is we left the operand cache in an inconsistent state because we called the new function too late. This is trivially fixed by making the transformation before we call update_stmt_if_modified. The irony here is the whole point of calling reduce_vector_comparison_to_scalar_comparison when we did was to expose these kinds of secondary opportunities. In this particular case we collapsed the test to a comparison of constants (thus no SSA operands). Anyway, this fixes the problem in the obvious way. This may all end up being moot if I can twiddle Richi's match.pd pattern to work. It doesn't work as-written due to a couple issues that I haven't worked totally through yet. Installed on the trunk after bootstrap & regression testing on x86 and verifying it addresses the aarch64 issue. gcc/ PR tree-optimization/102152 * tree-ssa-dom.c (dom_opt_dom_walker::optimize_stmt): Reduce a vector comparison to a scalar comparison before calling update_stmt_if_modified. gcc/testsuite/ PR tree-optimization/102152 * gcc.dg/pr102152.c: New test diff --git a/gcc/testsuite/gcc.dg/pr102152.c b/gcc/testsuite/gcc.dg/pr102152.c new file mode 100644 index 00000000000..4e0c1f5a3d5 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr102152.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -ftree-loop-vectorize -fno-tree-fre" } */ +/* { dg-additional-options "-march=armv8-a+sve" { target aarch64-*-* } } */ + + + +signed char i; + +void +foo (void) +{ + for (i = 0; i < 6; i += 5) + ; +} diff --git a/gcc/tree-ssa-dom.c b/gcc/tree-ssa-dom.c index a5245b33de6..49d8f96408f 100644 --- a/gcc/tree-ssa-dom.c +++ b/gcc/tree-ssa-dom.c @@ -1990,14 +1990,14 @@ dom_opt_dom_walker::optimize_stmt (basic_block bb, gimple_stmt_iterator *si, print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM); } - update_stmt_if_modified (stmt); - opt_stats.num_stmts++; - /* STMT may be a comparison of uniform vectors that we can simplify down to a comparison of scalars. Do that transformation first so that all the scalar optimizations from here onward apply. */ reduce_vector_comparison_to_scalar_comparison (stmt); + update_stmt_if_modified (stmt); + opt_stats.num_stmts++; + /* Const/copy propagate into USES, VUSES and the RHS of VDEFs. */ cprop_into_stmt (stmt, m_evrp_range_analyzer);