From patchwork Sat Aug 27 17:13:37 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Torvalds X-Patchwork-Id: 1104672 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7RHtufi015224 for ; Sat, 27 Aug 2011 17:55:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750974Ab1H0Rzx (ORCPT ); Sat, 27 Aug 2011 13:55:53 -0400 Received: from smtp1.linux-foundation.org ([140.211.169.13]:46446 "EHLO smtp1.linux-foundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750939Ab1H0Rzx (ORCPT ); Sat, 27 Aug 2011 13:55:53 -0400 Received: from mail-ww0-f44.google.com (mail-ww0-f44.google.com [74.125.82.44]) (authenticated bits=0) by smtp1.linux-foundation.org (8.14.2/8.13.5/Debian-3ubuntu1.1) with ESMTP id p7RHtpiT025882 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=FAIL) for ; Sat, 27 Aug 2011 10:55:52 -0700 Received: by wwf5 with SMTP id 5so4489697wwf.1 for ; Sat, 27 Aug 2011 10:55:50 -0700 (PDT) Received: by 10.216.178.142 with SMTP id f14mr1991181wem.85.1314467750367; Sat, 27 Aug 2011 10:55:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.187.66 with HTTP; Sat, 27 Aug 2011 10:13:37 -0700 (PDT) In-Reply-To: <201108271854.40694.kdudka@redhat.com> References: <4E588EB8.80808@garzik.org> <4E590F22.6030800@garzik.org> <201108271854.40694.kdudka@redhat.com> From: Linus Torvalds Date: Sat, 27 Aug 2011 10:13:37 -0700 Message-ID: Subject: Re: linearize bug? To: Kamil Dudka Cc: Jeff Garzik , Sparse Mailing-list , Pekka J Enberg X-Spam-Status: No, hits=-103.002 required=5 tests=AWL, BAYES_00, USER_IN_WHITELIST X-Spam-Checker-Version: SpamAssassin 3.2.4-osdl_revision__1.47__ X-MIMEDefang-Filter: lf$Revision: 1.188 $ X-Scanned-By: MIMEDefang 2.63 on 140.211.169.13 Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Sat, 27 Aug 2011 17:55:56 +0000 (UTC) On Sat, Aug 27, 2011 at 9:54 AM, Kamil Dudka wrote: > > It seems to break loops with no conditions.  The following piece of code: Yeah, good catch. I think it would be nicer to just teach "linearize_cond_branch()" that an empty condition is the same thing as an unconditional branch, that seems to be the most straightforward approach. But your patch is fine too. Linus cse.c | 7 ------- linearize.c | 23 ++++++++++++----------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/cse.c b/cse.c index 2a1574531993..2aabb65785f0 100644 --- a/cse.c +++ b/cse.c @@ -317,13 +317,6 @@ static struct instruction * try_to_cse(struct entrypoint *ep, struct instruction b2 = i2->bb; /* - * PHI-nodes do not care where they are - the only thing that matters - * are the PHI _sources_. - */ - if (i1->opcode == OP_PHI) - return cse_one_instruction(i1, i2); - - /* * Currently we only handle the uninteresting degenerate case where * the CSE is inside one basic-block. */ diff --git a/linearize.c b/linearize.c index f2034ce93572..4b4916340859 100644 --- a/linearize.c +++ b/linearize.c @@ -1419,9 +1419,14 @@ pseudo_t linearize_cond_branch(struct entrypoint *ep, struct expression *expr, s { pseudo_t cond; - if (!expr || !bb_reachable(ep->active)) + if (!bb_reachable(ep->active)) return VOID; + if (!expr) { + add_goto(ep, bb_true); + return VOID; + } + switch (expr->type) { case EXPR_STRING: @@ -2055,21 +2060,15 @@ pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt) struct statement *statement = stmt->iterator_statement; struct statement *post_statement = stmt->iterator_post_statement; struct expression *post_condition = stmt->iterator_post_condition; - struct basic_block *loop_top, *loop_body, *loop_continue, *loop_end; + struct basic_block *loop_body, *loop_continue, *loop_end; concat_symbol_list(stmt->iterator_syms, &ep->syms); linearize_statement(ep, pre_statement); - loop_body = loop_top = alloc_basic_block(ep, stmt->pos); + loop_body = alloc_basic_block(ep, stmt->pos); loop_continue = alloc_basic_block(ep, stmt->pos); loop_end = alloc_basic_block(ep, stmt->pos); - /* An empty post-condition means that it's the same as the pre-condition */ - if (!post_condition) { - loop_top = alloc_basic_block(ep, stmt->pos); - set_activeblock(ep, loop_top); - } - if (pre_condition) linearize_cond_branch(ep, pre_condition, loop_body, loop_end); @@ -2082,10 +2081,12 @@ pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt) set_activeblock(ep, loop_continue); linearize_statement(ep, post_statement); + + /* No post-condition means that it's the same as the pre-condition */ if (!post_condition) - add_goto(ep, loop_top); + linearize_cond_branch(ep, pre_condition, loop_body, loop_end); else - linearize_cond_branch(ep, post_condition, loop_top, loop_end); + linearize_cond_branch(ep, post_condition, loop_body, loop_end); set_activeblock(ep, loop_end); break; }