From 2aa7d268e2ce37025d68a3f428001f6f779f56e8 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 21 May 2020 23:36:09 -0700 Subject: [PATCH 876/977] optimize: fix some of those changes. For loops with predecrements that we eliminated because we don't want to rely on the loop index going negative if it's zero before the predecrement - the index is now unsigned, so it'll *never go negative - we revert to a similar loop, but with the test checking whether the index is 0 and decrementing it as the first action in the loop body. (Yeah, it means that, on machines with condition codes, you don't get to use the condition code setting of the decrement "for free"; we'll let the compiler and the processor figure out how to do that efficiently.) --- optimize.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/optimize.c b/optimize.c index bea8cdc..07fc0f3 100644 --- a/optimize.c +++ b/optimize.c @@ -427,20 +427,18 @@ find_dom(opt_state_t *opt_state, struct block *root) */ x = opt_state->all_dom_sets; /* - * These are both guaranteed to be > 0, so the product is - * guaranteed to be > 0. - * - * XXX - but what if it overflows? + * XXX - what if the multiplication overflows? */ i = opt_state->n_blocks * opt_state->nodewords; - do + while (i != 0) { + --i; *x++ = 0xFFFFFFFFU; - while (--i != 0); + } /* Root starts off empty. */ - i = opt_state->nodewords; - do + for (i = opt_state->nodewords; i != 0;) { + --i; root->dom[i] = 0; - while (--i != 0); + } /* root->level is the highest level no found. */ for (level = root->level; level >= 0; --level) { @@ -478,15 +476,12 @@ find_edom(opt_state_t *opt_state, struct block *root) x = opt_state->all_edge_sets; /* - * These are both guaranteed to be > 0, so the product is - * guaranteed to be > 0. - * - * XXX - but what if it overflows? + * XXX - what if the multiplication overflows? */ - i = opt_state->n_edges * opt_state->edgewords; - do + for (i = opt_state->n_edges * opt_state->edgewords; i != 0; ) { + --i; x[i] = 0xFFFFFFFFU; - while (--i != 0); + } /* root->level is the highest level no found. */ memset(root->et.edom, 0, opt_state->edgewords * sizeof(*(uset)0)); @@ -2138,17 +2133,19 @@ link_inedge(struct edge *parent, struct block *child) static void find_inedges(opt_state_t *opt_state, struct block *root) { + u_int i; + int level; struct block *b; - for (u_int i = 0; i < opt_state->n_blocks; ++i) + for (i = 0; i < opt_state->n_blocks; ++i) opt_state->blocks[i]->in_edges = 0; /* * Traverse the graph, adding each edge to the predecessor * list of its successors. Skip the leaves (i.e. level 0). */ - for (int i = root->level; i > 0; --i) { - for (b = opt_state->levels[i]; b != 0; b = b->link) { + for (level = root->level; level > 0; --level) { + for (b = opt_state->levels[level]; b != 0; b = b->link) { link_inedge(&b->et, JT(b)); link_inedge(&b->ef, JF(b)); } -- 1.8.3.1