From patchwork Wed Mar 21 14:58:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Razya Ladelsky X-Patchwork-Id: 147990 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]) by ozlabs.org (Postfix) with SMTP id 2BAC6B6EEF for ; Thu, 22 Mar 2012 01:59:10 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1332946751; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:To:MIME-Version:Subject:From: Message-ID:Date:Content-Type:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=qrWxOHuzrVJ0tRCa8Y6sE1jh2L0=; b=XeQ0knsRYDeghNh Eo791JMAcyjFyOFW2xmqUpMvDSoJntTf+HgsRfIMQejQFA/hPXffdkb2/XODVaak VAQIeJKrVCRtVntyW+bZ/HR7qYcLar8iH1aOIb3GaSuxiK11CQj3k91EMAo4DldM k40aV0GC8rzFgiHJZmbChoMEYuIk= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Received:To:MIME-Version:Subject:X-KeepSent:From:Message-ID:Date:Content-Type:x-cbid:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=d72s5MkHvwVjwR40uuhhX0GgjIMBi4rTROuYnBjikR3V50+woWtKC4DbBpzjFH 96idqtaZ2+1CQd0SdFPyHdtFEWLLrudtSdzPDex/V/1h6x3mPr+CoK/ub9/p140S //JCYopRUqX1NxN8YwdNZwGTEB1cXHryzRh4vxE6dVzIo=; Received: (qmail 21286 invoked by alias); 21 Mar 2012 14:59:04 -0000 Received: (qmail 21277 invoked by uid 22791); 21 Mar 2012 14:59:02 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from e06smtp16.uk.ibm.com (HELO e06smtp16.uk.ibm.com) (195.75.94.112) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 21 Mar 2012 14:58:49 +0000 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 21 Mar 2012 14:58:47 -0000 Received: from d06nrmr1806.portsmouth.uk.ibm.com (9.149.39.193) by e06smtp16.uk.ibm.com (192.168.101.146) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 21 Mar 2012 14:58:45 -0000 Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by d06nrmr1806.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q2LEwicn2875492 for ; Wed, 21 Mar 2012 14:58:44 GMT Received: from d06av06.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q2LEwiiW022761 for ; Wed, 21 Mar 2012 08:58:44 -0600 Received: from d06ml319.portsmouth.uk.ibm.com (d06ml319.portsmouth.uk.ibm.com [9.149.76.146]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q2LEwh9X022754; Wed, 21 Mar 2012 08:58:44 -0600 To: Richard Guenther , GCC Patches MIME-Version: 1.0 Subject: [RFC][PATCH] A change to do_while_loop_p() X-KeepSent: F3E28F9B:CAE5BF5B-C22579C8:004EFC6A; type=4; name=$KeepSent From: Razya Ladelsky Message-ID: Date: Wed, 21 Mar 2012 16:58:37 +0200 x-cbid: 12032114-3548-0000-0000-0000016783E2 X-IsSubscribed: yes 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 Hi, I need to use do_while_loop_p, but I'm not sure its functionality is what I expected it to be. This is the part that I do not understand: /* If the header contains just a condition, it is not a do-while loop. */ stmt = last_and_only_stmt (loop->header); if (stmt && gimple_code (stmt) == GIMPLE_COND) return false; The header could contain a condition which is not the loop's exit condition, but rather a part of its body, then why do we rule out this loop as a do_while loop? I ran into this in a loop (the outer loop) extracted from bwaves benchmark: do k=1,nz km1=mod(k+nz-2,nz)+1 kp1=mod(k,nz)+1 do j=1,ny jm1=mod(j+ny-2,ny)+1 jp1=mod(j,ny)+1 ..... enddo enddo which was translated to: D.2361_17 = *ny_16(D); : # k_3 = PHI <1(4), k_562(25)> if (D.2361_17 > 0) goto ; else goto ; : k_562 = k_3 + 1; # DEBUG k => k_562 if (k_3 == D.1583_270) goto ; -------> return else goto ; : goto ; : --> starting the body of the the second loop pretmp.318_776 = (integer(kind=8)) k_3; pretmp.318_777 = stride.92_20 * pretmp.318_776; ....... bb 5 is the header of the outer loop, and bb 25 is the latch. According to do_while_loop_p () this is NOT a do while loop, but it seems that it should be. I am attaching a patch to change do_while_loop_p() assuming that what I understand is indeed correct, Please let me know if I'm right, Thank you, Razya = Index: tree-ssa-loop-ch.c =================================================================== --- tree-ssa-loop-ch.c (revision 185604) +++ tree-ssa-loop-ch.c (working copy) @@ -107,6 +107,8 @@ should_duplicate_loop_header_p (basic_block header bool do_while_loop_p (struct loop *loop) { + edge exit_edge; + gimple cond_stmt; gimple stmt = last_stmt (loop->latch); /* If the latch of the loop is not empty, it is not a do-while loop. */ @@ -116,8 +118,14 @@ do_while_loop_p (struct loop *loop) /* If the header contains just a condition, it is not a do-while loop. */ stmt = last_and_only_stmt (loop->header); + exit_edge = single_dom_exit (loop); + if (exit_edge) + cond_stmt = last_stmt (exit_edge->src); + else + cond_stmt =stmt; if (stmt - && gimple_code (stmt) == GIMPLE_COND) + && gimple_code (stmt) == GIMPLE_COND + && stmt == cond_stmt) return false; return true;