From patchwork Sun Nov 19 14:46:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 839328 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-467327-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mfyWvSrx"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yfvn15nR3z9rxm for ; Mon, 20 Nov 2017 01:46:26 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=CqiTf9ME1YVMOv/BGCdu2CyAt02sWzFFSn8FL7b1e4wvMgefMOvm4 /Rh5XXT2wdhPEZvil2iHr6vR3z5tsCWyKK0vdzfJr4iD0X13GYSoF8LZaAYuPqE1 m8JvRrG4flgxs14OUQy4hE/71uIw2sMsNzFd0FHfG44DjzXGWiR1IQ= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=CcU+e/rYOljsqzk3+36qMglbcyE=; b=mfyWvSrxuH/ugpw8b3z6 Fkvk8hZbwiadZ3s8N1B4kB4LQWae9/QjGFytzbp2c2k+YKce1aB9EHXM7a7S6kWa vRg/g+692PHy+xzKdFDhCbFd367wET3g4PdPBrGt5d3uGkbwZpiKJuQ5GpOpuAb9 J04RY72emPoCdLke1xh1JMI= Received: (qmail 23787 invoked by alias); 19 Nov 2017 14:46:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 23772 invoked by uid 89); 19 Nov 2017 14:46:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.2 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KB_WAM_FROM_NAME_SINGLEWORD, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=HTo:U*wilson, H*Ad:D*il.ibm.com, HTo:D*il.ibm.com, average X-HELO: nikam.ms.mff.cuni.cz Received: from nikam.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 19 Nov 2017 14:46:15 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id E4118546E89; Sun, 19 Nov 2017 15:46:11 +0100 (CET) Date: Sun, 19 Nov 2017 15:46:11 +0100 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, zaks@il.ibm.com, gnu@the-meissners.org, vmakarov@redhat.com, law@redhat.com, wilson@tuliptree.org Subject: Fix PR82849 (ICE in modulo scheduling) Message-ID: <20171119144611.GA20392@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Hi, my understanding of the code is that trip_count is trying to estimate number of iterations when counts are available and disable modulo scheduler for loops with too few iterations. We now have get_estimated_loop_iterations_int and get_max_loop_iterations_int which keeps information detected upstream and so we should use i there. I tested the patch very lightly only on the testcase in question as I am not sure when and how modulo sched is used. Seems sane? What are the code size impacts of modulo scheduling? Honza PR 82849 * modulo-sched.c (sms_schedule): Use get_estimated_loop_iterations_int and get_max_loop_iterations_int. Index: modulo-sched.c =================================================================== --- modulo-sched.c (revision 254929) +++ modulo-sched.c (working copy) @@ -1346,7 +1346,7 @@ sms_schedule (void) struct loop *loop; basic_block condition_bb = NULL; edge latch_edge; - gcov_type trip_count = 0; + HOST_WIDE_INT trip_count, max_trip_count; loop_optimizer_init (LOOPS_HAVE_PREHEADERS | LOOPS_HAVE_RECORDED_EXITS); @@ -1422,9 +1422,8 @@ sms_schedule (void) get_ebb_head_tail (bb, bb, &head, &tail); latch_edge = loop_latch_edge (loop); gcc_assert (single_exit (loop)); - if (single_exit (loop)->count () > profile_count::zero ()) - trip_count = latch_edge->count ().to_gcov_type () - / single_exit (loop)->count ().to_gcov_type (); + trip_count = get_estimated_loop_iterations_int (loop); + max_trip_count = get_max_loop_iterations_int (loop); /* Perform SMS only on loops that their average count is above threshold. */ @@ -1444,8 +1443,8 @@ sms_schedule (void) (int64_t) bb->count.to_gcov_type ()); fprintf (dump_file, "\n"); fprintf (dump_file, "SMS trip-count "); - fprintf (dump_file, "%" PRId64, - (int64_t) trip_count); + fprintf (dump_file, "%" PRId64 "max %" PRId64, + (int64_t) trip_count, (int64_t) max_trip_count); fprintf (dump_file, "\n"); fprintf (dump_file, "SMS profile-sum-max "); fprintf (dump_file, "%" PRId64, @@ -1552,9 +1551,8 @@ sms_schedule (void) latch_edge = loop_latch_edge (loop); gcc_assert (single_exit (loop)); - if (single_exit (loop)->count ()> profile_count::zero ()) - trip_count = latch_edge->count ().to_gcov_type () - / single_exit (loop)->count ().to_gcov_type (); + trip_count = get_estimated_loop_iterations_int (loop); + max_trip_count = get_max_loop_iterations_int (loop); if (dump_file) { @@ -1648,7 +1646,8 @@ sms_schedule (void) we let the scheduling passes do the job in this case. */ if (stage_count < PARAM_VALUE (PARAM_SMS_MIN_SC) || (count_init && (loop_count <= stage_count)) - || (flag_branch_probabilities && (trip_count <= stage_count))) + || (max_trip_count >= 0 && max_trip_count <= stage_count) + || (trip_count >= 0 && trip_count <= stage_count)) { if (dump_file) { @@ -1657,7 +1656,8 @@ sms_schedule (void) " loop-count=", stage_count); fprintf (dump_file, "%" PRId64, loop_count); fprintf (dump_file, ", trip-count="); - fprintf (dump_file, "%" PRId64, trip_count); + fprintf (dump_file, "%" PRId64 "max %" PRId64, + (int64_t) trip_count, (int64_t) max_trip_count); fprintf (dump_file, ")\n"); } break;