From patchwork Thu May 22 21:36:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dehao Chen X-Patchwork-Id: 351622 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 B64F014007C for ; Fri, 23 May 2014 07:36:35 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=qzz85AsQ31ksP9hh5OlD3ivcRQoqPmMvpLjn8l7z7QN i/Kk7HIZkKLH/Huimq5rQ+8OzoISt8WhZ2oCepdmve9GVDGO3VUX3P8SBi4QMsge kXaqVSuyCHX138sfOaGWWpC6s15FGONxAi5cMkEJ6hVCBPanPmRbxutqaMKUfU7Y = 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 :mime-version:date:message-id:subject:from:to:cc:content-type; s=default; bh=Zjbfv0W5E7sKrOp9QQYGo42F908=; b=YCm6HImrWaTj8CKCY /4857unDdQEZ1H3y6p3QXIlCd8Th6tzhl8rpe6WZNSH45as6ET1SUdaAw1jvuV4X aQbflrJqhntkIdFfIvyTaH9NCvJlrAHZkuXByh6GQ/x9ZcmMXfCqWBVIqnpkIEsD g5hQcCaVpzMXPkFwRFyy4sOyj4= Received: (qmail 12714 invoked by alias); 22 May 2014 21:36:28 -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 12700 invoked by uid 89); 22 May 2014 21:36:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ie0-f172.google.com Received: from mail-ie0-f172.google.com (HELO mail-ie0-f172.google.com) (209.85.223.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 22 May 2014 21:36:26 +0000 Received: by mail-ie0-f172.google.com with SMTP id tp5so4256896ieb.3 for ; Thu, 22 May 2014 14:36:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to:cc :content-type; bh=MeIw238WuXrSXOEFDXEtVvb0Fgmm5e2v2IyKgmTQRBA=; b=g/fDyS9gmMzVGJufp7wEPFDbUk8UwNP2O8ODhExtA9cblyDKa4zR++ugn53kYDt3/U 7lvVIQEj6Y1PFC7s1LPkS1KHg3mj+OW8A/vg4HzpMXPZ22GciHXFRd+EPHICNcRT3TxS e+Q2LgST5omaqh+2dYr0Fh5PMeqauRqCyP+ZXoTfRzf7UqX+vUSwunWWmsm2IVSjmckb Cd3o6+zX6qDzv6NV5oIdaXWTa4hsJry2NFK9cR/pjkAjMQ/0OTz7EVmnPeCeqWM0Rsfy d9yqIM5p4aKnmUVlGyfZJ1C46Wf6XhjjDqoLqYM81aPf8WSILOt7nbzW0Sw7OsopOatT iOnQ== X-Gm-Message-State: ALoCoQmSDhp+o7zvlNnpsZCuPmk0n2wtBHOut3SLtmCupG1Jx9ZbAxUkGGsax3SIYZf7TFjR0/lV MIME-Version: 1.0 X-Received: by 10.50.131.138 with SMTP id om10mr25496400igb.25.1400794584373; Thu, 22 May 2014 14:36:24 -0700 (PDT) Received: by 10.64.240.97 with HTTP; Thu, 22 May 2014 14:36:24 -0700 (PDT) Date: Thu, 22 May 2014 14:36:24 -0700 Message-ID: Subject: [PATCH] Disable unroll loop that has header count less than iteration count. From: Dehao Chen To: GCC Patches Cc: Jan Hubicka , David Li X-IsSubscribed: yes If a loop's header count is less than iteration count, the iteration estimation is apparently incorrect for this loop. Thus disable unrolling of such loops. Testing on going. OK for trunk if test pass? Thanks, Dehao gcc/ChangeLog: 2014-05-21 Dehao Chen * cfgloop.h (expected_loop_iterations_reliable_p): New func. * cfgloopanal.c (expected_loop_iterations_reliable_p): Likewise. * loop-unroll.c (decide_unroll_runtime_iterations): Disable unroll loop that has unreliable iteration counts. Index: gcc/cfgloop.h =================================================================== --- gcc/cfgloop.h (revision 210717) +++ gcc/cfgloop.h (working copy) @@ -307,8 +307,8 @@ extern bool just_once_each_iteration_p (const stru gcov_type expected_loop_iterations_unbounded (const struct loop *); extern unsigned expected_loop_iterations (const struct loop *); extern rtx doloop_condition_get (rtx); +extern bool expected_loop_iterations_reliable_p (const struct loop *); - /* Loop manipulation. */ extern bool can_duplicate_loop_p (const struct loop *loop); Index: gcc/cfgloopanal.c =================================================================== --- gcc/cfgloopanal.c (revision 210717) +++ gcc/cfgloopanal.c (working copy) @@ -285,6 +285,15 @@ expected_loop_iterations (const struct loop *loop) return (expected > REG_BR_PROB_BASE ? REG_BR_PROB_BASE : expected); } +/* Returns true if the loop header's profile count is smaller than expected + loop iteration. */ + +bool +expected_loop_iterations_reliable_p (const struct loop *loop) +{ + return expected_loop_iterations (loop) < loop->header->count; +} + /* Returns the maximum level of nesting of subloops of LOOP. */ unsigned Index: gcc/loop-unroll.c =================================================================== --- gcc/loop-unroll.c (revision 210717) +++ gcc/loop-unroll.c (working copy) @@ -988,6 +988,15 @@ decide_unroll_runtime_iterations (struct loop *loo return; } + if (profile_status_for_fn (cfun) == PROFILE_READ + && expected_loop_iterations_reliable_p (loop)) + { + if (dump_file) + fprintf (dump_file, ";; Not unrolling loop, loop iteration " + "not reliable."); + return; + } + /* Check whether the loop rolls. */ if ((get_estimated_loop_iterations (loop, &iterations) || get_max_loop_iterations (loop, &iterations))