From patchwork Thu Mar 19 09:00:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1258041 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.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=IiwdNmIE; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 48jgqS4xPHz9sPR for ; Thu, 19 Mar 2020 20:00:52 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 410DE3877008; Thu, 19 Mar 2020 09:00:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 410DE3877008 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1584608449; bh=RRVlH8fdv/jkPAVN8bPkvsDxrAgmhBK57RkV7mJfRKY=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=IiwdNmIEluPhRr3QnhkO6JIparRGdIFfmcsFQEdtlYG1wgx9Pv9iErVaG0cyXIUBU jRWbQId4VhTmRupSN0r6zlB2IgG7YaJv7+u5cwnTRKKAzrO/nTlwwh+N7UyxPqHpIu fseRDtkZa0l9gLcFZt/LlcQRxB4myfjuEE8FG2Ao= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [63.128.21.74]) by sourceware.org (Postfix) with ESMTP id B24723877008 for ; Thu, 19 Mar 2020 09:00:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B24723877008 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-482-DvqexxhcM1GGnZrOWsbcjg-1; Thu, 19 Mar 2020 05:00:44 -0400 X-MC-Unique: DvqexxhcM1GGnZrOWsbcjg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A2D7C18B9FC3; Thu, 19 Mar 2020 09:00:43 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A39A60BEC; Thu, 19 Mar 2020 09:00:43 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 02J90fEj029221; Thu, 19 Mar 2020 10:00:41 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 02J90eSC029220; Thu, 19 Mar 2020 10:00:40 +0100 Date: Thu, 19 Mar 2020 10:00:40 +0100 To: Richard Biener Subject: [PATCH] phiopt: Avoid -fcompare-debug bug in phiopt [PR94211] Message-ID: <20200319090040.GO2156@tucnak> MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-10.2 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: "Li, Pan2 via Gcc-patches" Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! Two years ago, I've added support for up to 2 simple preparation statements in value_replacement, but the - && estimate_num_insns (assign, &eni_time_weights) + && estimate_num_insns (bb_seq (middle_bb), &eni_time_weights) change, meant that we compute the cost of all those statements rather than just the single assign that has been the single supported non-debug statement in the bb before, doesn't do what I thought would do, gimple_seq is just gimple * and thus it can't be really overloaded depending on whether we pass a single gimple * or a whole sequence. Which means in the last two years it doesn't count all the statements, but only the first one. With -g that happens to be a DEBUG_STMT, or it could be e.g. the first preparation statement which could be much cheaper than the actual assign. Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2020-03-19 Jakub Jelinek PR tree-optimization/94211 * tree-ssa-phiopt.c (value_replacement): Use estimate_num_insns_seq instead of estimate_num_insns for bb_seq (middle_bb). Rename emtpy_or_with_defined_p variable to empty_or_with_defined_p, adjust all uses. * gcc.dg/pr94211.c: New test. Jakub --- gcc/tree-ssa-phiopt.c.jj 2020-03-16 23:49:29.853404202 +0100 +++ gcc/tree-ssa-phiopt.c 2020-03-18 19:42:22.583225152 +0100 @@ -1056,7 +1056,7 @@ value_replacement (basic_block cond_bb, gimple *cond; edge true_edge, false_edge; enum tree_code code; - bool emtpy_or_with_defined_p = true; + bool empty_or_with_defined_p = true; /* If the type says honor signed zeros we cannot do this optimization. */ @@ -1075,7 +1075,7 @@ value_replacement (basic_block cond_bb, { if (gimple_code (stmt) != GIMPLE_PREDICT && gimple_code (stmt) != GIMPLE_NOP) - emtpy_or_with_defined_p = false; + empty_or_with_defined_p = false; continue; } /* Now try to adjust arg0 or arg1 according to the computation @@ -1085,7 +1085,7 @@ value_replacement (basic_block cond_bb, && jump_function_from_stmt (&arg0, stmt)) || (lhs == arg1 && jump_function_from_stmt (&arg1, stmt))) - emtpy_or_with_defined_p = false; + empty_or_with_defined_p = false; } cond = last_stmt (cond_bb); @@ -1137,7 +1137,7 @@ value_replacement (basic_block cond_bb, /* If the middle basic block was empty or is defining the PHI arguments and this is a single phi where the args are different for the edges e0 and e1 then we can remove the middle basic block. */ - if (emtpy_or_with_defined_p + if (empty_or_with_defined_p && single_non_singleton_phi_for_edges (phi_nodes (gimple_bb (phi)), e0, e1) == phi) { @@ -1255,7 +1255,7 @@ value_replacement (basic_block cond_bb, && profile_status_for_fn (cfun) != PROFILE_ABSENT && EDGE_PRED (middle_bb, 0)->probability < profile_probability::even () /* If assign is cheap, there is no point avoiding it. */ - && estimate_num_insns (bb_seq (middle_bb), &eni_time_weights) + && estimate_num_insns_seq (bb_seq (middle_bb), &eni_time_weights) >= 3 * estimate_num_insns (cond, &eni_time_weights)) return 0; --- gcc/testsuite/gcc.dg/pr94211.c.jj 2020-03-18 16:30:34.562427467 +0100 +++ gcc/testsuite/gcc.dg/pr94211.c 2020-03-18 16:30:19.998640206 +0100 @@ -0,0 +1,12 @@ +/* PR tree-optimization/94211 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fcompare-debug" } */ + +long +foo (long a, long b) +{ + if (__builtin_expect (b == 1, 1)) + return a; + int e = a + 1; + return a / b; +}