aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2004-12-05 15:31:02 +0000
committerRoger Sayle <sayle@gcc.gnu.org>2004-12-05 15:31:02 +0000
commit28af952a24ef13bf1e2ad7967f0c5a55ae01cdf7 (patch)
tree73004ed81c4bf30c3d2a5efe6eb0ade2e3722cd5 /gcc
parent118f3b19a39403f6b9391ff9f89a38e8248f43f9 (diff)
downloadgcc-28af952a24ef13bf1e2ad7967f0c5a55ae01cdf7.zip
gcc-28af952a24ef13bf1e2ad7967f0c5a55ae01cdf7.tar.gz
gcc-28af952a24ef13bf1e2ad7967f0c5a55ae01cdf7.tar.bz2
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-typeck.c17
2 files changed, 17 insertions, 5 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8db2947..6b3b015 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2004-12-05 Roger Sayle <roger@eyesopen.com>
+
+ * c-typeck.c (c_finish_loop): Improve initial implementations
+ for loops whose conditions are known at compile-time.
+
2004-12-05 Kazu Hirata <kazu@cs.umass.edu>
* builtins.c: Fix comment typos.
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 23ff80e..f2f9b4d 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