From patchwork Mon Jul 22 16:12:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1963327 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=ucw.cz header.i=@ucw.cz header.a=rsa-sha256 header.s=gen1 header.b=Nco2Xn2K; 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 4WSQLF5n1dz1ybY for ; Tue, 23 Jul 2024 02:13:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 001F2385DDC0 for ; Mon, 22 Jul 2024 16:13:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id 171C6385840A for ; Mon, 22 Jul 2024 16:12:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 171C6385840A Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=ucw.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kam.mff.cuni.cz ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 171C6385840A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.113.20.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721664766; cv=none; b=nPpMfHGWX4tCyKdRjr5+kesRq43Vk+k20tf3XBQ25rrzVM94w1MYDh7tDhEqA+Qija1lWYJ+mVqu/MxWiWOWPEPvxuZVaIk8Qz23t3dYpwF0tE2tG1MsDuj7x07w0U02vuBfmtb71+u5hoFBpYLSii/3sIWCvNZ08MHLbf46rnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721664766; c=relaxed/simple; bh=j1Y1ExB1PpaqQ26NmVArouTbXLM/EKdZiQofCvF0VPE=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=bxoydo1pYGuFzvK6rdUP/Z/jaSEU42v3P1oXEx5iIe2rkMZraCuBf28prrBaa3Y20vp5cJMIEAXx2P0bjK6SVvJPQMbWUHWXJ1BuPMfnygpL1XUYouA8K6dR777kCLj65Ca3lLgTSNhgUfRbP/isETOkAyiBi3Lay16snhGQVuA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 4563E2814CA; Mon, 22 Jul 2024 18:12:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ucw.cz; s=gen1; t=1721664763; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=bS4fIJ1wQ2a8gapQhPYfEpDSO0HgBIFfIH6+R4pRPhE=; b=Nco2Xn2KRPAvi/g955n1vp3m2aOgrNbDdFJtuWjkAZrkdtjrozpyN2ueYNJqvC3In9vVpX Cd1/Q8ZDUXdYnzEtc5Lm3KOUfKGdH8zd0c9DDW/sYByTpbX1GzNLANMrdf68fmu+EfXq0L xfdw8e6mAPghQ+N3G60M1QHKzSIj8KY= Date: Mon, 22 Jul 2024 18:12:43 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org Subject: Compare loop bounds in ipa-icf Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, JMQ_SPF_NEUTRAL, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Hi, this testcase shows another poblem with missing comparators for metadata in ICF. With value ranges available to loop optimizations during early opts we can estimate number of iterations based on guarding condition that can be split away by the fnsplit pass. This patch disables ICF when number of iteraitons does not match. Bootstrapped/regtesed x86_64-linux, comitted. Will backport it to gcc14. gcc/ChangeLog: PR ipa/115277 * ipa-icf-gimple.cc (func_checker::compare_loops): gcc/testsuite/ChangeLog: * gcc.c-torture/compile/pr115277.c: New test. diff --git a/gcc/ipa-icf-gimple.cc b/gcc/ipa-icf-gimple.cc index c25eb24710f..4c3174b68b6 100644 --- a/gcc/ipa-icf-gimple.cc +++ b/gcc/ipa-icf-gimple.cc @@ -543,6 +543,10 @@ func_checker::compare_loops (basic_block bb1, basic_block bb2) return return_false_with_msg ("unroll"); if (!compare_variable_decl (l1->simduid, l2->simduid)) return return_false_with_msg ("simduid"); + if ((l1->any_upper_bound != l2->any_upper_bound) + || (l1->any_upper_bound + && (l1->nb_iterations_upper_bound != l2->nb_iterations_upper_bound))) + return return_false_with_msg ("nb_iterations_upper_bound"); return true; } diff --git a/gcc/testsuite/gcc.c-torture/compile/pr115277.c b/gcc/testsuite/gcc.c-torture/compile/pr115277.c new file mode 100644 index 00000000000..27449eb254f --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr115277.c @@ -0,0 +1,28 @@ +int array[1000]; +void +test (int a) +{ + if (__builtin_expect (a > 3, 1)) + return; + for (int i = 0; i < a; i++) + array[i]=i; +} +void +test2 (int a) +{ + if (__builtin_expect (a > 10, 1)) + return; + for (int i = 0; i < a; i++) + array[i]=i; +} +int +main() +{ + test(1); + test(2); + test(3); + test2(10); + if (array[9] != 9) + __builtin_abort (); + return 0; +}