From 28af952a24ef13bf1e2ad7967f0c5a55ae01cdf7 Mon Sep 17 00:00:00 2001 From: Roger Sayle Date: Sun, 5 Dec 2004 15:31:02 +0000 Subject: [PATCH] c-typeck.c (c_finish_loop): Improve initial implementations for loops whose conditions are known at... * c-typeck.c (c_finish_loop): Improve initial implementations for loops whose conditions are known at compile-time. From-SVN: r91750 --- gcc/ChangeLog | 5 +++++ gcc/c-typeck.c | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8db2947625a..6b3b015fa2d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2004-12-05 Roger Sayle + + * c-typeck.c (c_finish_loop): Improve initial implementations + for loops whose conditions are known at compile-time. + 2004-12-05 Kazu Hirata * builtins.c: Fix comment typos. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 23ff80e10de..f2f9b4daa45 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -6659,10 +6659,17 @@ c_finish_loop (location_t start_locus, tree cond, tree incr, tree body, { tree entry = NULL, exit = NULL, t; - /* Detect do { ... } while (0) and don't generate loop construct. */ - if (cond && !cond_is_first && integer_zerop (cond)) - cond = NULL; - if (cond_is_first || cond) + /* If the condition is zero don't generate a loop construct. */ + if (cond && integer_zerop (cond)) + { + if (cond_is_first) + { + t = build_and_jump (&blab); + SET_EXPR_LOCATION (t, start_locus); + add_stmt (t); + } + } + else { tree top = build1 (LABEL_EXPR, void_type_node, NULL_TREE); @@ -6671,7 +6678,7 @@ c_finish_loop (location_t start_locus, tree cond, tree incr, tree body, then we just build a jump back to the top. */ exit = build_and_jump (&LABEL_EXPR_LABEL (top)); - if (cond) + if (cond && !integer_nonzerop (cond)) { /* Canonicalize the loop condition to the end. This means generating a branch to the loop condition. Reuse the -- 2.30.2