From patchwork Fri Jan 28 16:31:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 50531 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 E1E5D385F026 for ; Fri, 28 Jan 2022 16:32:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E1E5D385F026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1643387520; bh=wY1iLmz2QW8W8gXD/Annl0qJzZE21j9vJ3CweibK32c=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Ua0N10Y9GVVyH8rXTtlhPc2P0PIMl3D8uSdiRA8hcBMBTqvCPVhr/EFBSL1jkJ7RR iEkyxyqArhMHLd69KPqFXGyA7+sudLTVyYav4TknVBnuKOi9qDdaqZaoKEkxV15p+o 9by7T4FhtowVTmbDH0Rv5hVgDvrV5LV0uWxBRKJw= 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 BE3C4385840C for ; Fri, 28 Jan 2022 16:31:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BE3C4385840C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-544-_nC2Z_fkNam7nSF3QOgh6Q-1; Fri, 28 Jan 2022 11:31:29 -0500 X-MC-Unique: _nC2Z_fkNam7nSF3QOgh6Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 939D01083F62; Fri, 28 Jan 2022 16:31:28 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2ABFC74EAD; Fri, 28 Jan 2022 16:31:28 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 20SGVPIM3392194 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 28 Jan 2022 17:31:25 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 20SGVOM33392193; Fri, 28 Jan 2022 17:31:24 +0100 Date: Fri, 28 Jan 2022 17:31:24 +0100 To: Richard Biener Subject: [PATCH] store-merging: Fix up a -fcompare-debug bug in get_status_for_store_merging [PR104263] Message-ID: <20220128163124.GQ2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! As mentioned in the PRthe following testcase fails, because the last stmt of a bb with -g is a debug stmt and get_status_for_store_merging uses gimple_seq_last_stmt (bb_seq (bb)) when testing if it is valid for store merging. The debug stmt isn't valid, while a stmt at that position with -g0 is valid and so the divergence. As we walk the whole bb already, this patch just remembers the last non-debug stmt, so that we don't need to skip backwards debug stmts at the end of the bb to find last real stmt. Bootstrapped/regtested on powerpc64le-linux, ok for trunk? 2022-01-28 Jakub Jelinek PR tree-optimization/104263 * gimple-ssa-store-merging.cc (get_status_for_store_merging): For cfun->can_throw_non_call_exceptions && cfun->eh test whether last non-debug stmt in the bb is store_valid_for_store_merging_p rather than last stmt. * gcc.dg/pr104263.c: New test. Jakub --- gcc/gimple-ssa-store-merging.cc.jj 2022-01-20 11:30:45.521578942 +0100 +++ gcc/gimple-ssa-store-merging.cc 2022-01-28 11:27:25.437947561 +0100 @@ -5364,6 +5364,7 @@ get_status_for_store_merging (basic_bloc unsigned int num_constructors = 0; gimple_stmt_iterator gsi; edge e; + gimple *last_stmt = NULL; for (gsi = gsi_after_labels (bb); !gsi_end_p (gsi); gsi_next (&gsi)) { @@ -5372,6 +5373,8 @@ get_status_for_store_merging (basic_bloc if (is_gimple_debug (stmt)) continue; + last_stmt = stmt; + if (store_valid_for_store_merging_p (stmt) && ++num_statements >= 2) break; @@ -5398,7 +5401,7 @@ get_status_for_store_merging (basic_bloc return BB_INVALID; if (cfun->can_throw_non_call_exceptions && cfun->eh - && store_valid_for_store_merging_p (gimple_seq_last_stmt (bb_seq (bb))) + && store_valid_for_store_merging_p (last_stmt) && (e = find_fallthru_edge (bb->succs)) && e->dest == bb->next_bb) return BB_EXTENDED_VALID; --- gcc/testsuite/gcc.dg/pr104263.c.jj 2022-01-28 11:32:26.718619588 +0100 +++ gcc/testsuite/gcc.dg/pr104263.c 2022-01-28 11:32:04.111944459 +0100 @@ -0,0 +1,25 @@ +/* PR tree-optimization/104263 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcompare-debug -fnon-call-exceptions -fno-inline-small-functions" } */ + +int n; + +int +bar (void) +{ + int a; + + n = 0; + a = 0; + + return n; +} + +__attribute__ ((pure, returns_twice)) int +foo (void) +{ + n = bar () + 1; + foo (); + + return 0; +}