The current implementation of this function is somewhat difficult to understand, as it uses a direct break statement within the for loop, rendering the loop meaningless. Additionally, during the Coverity check on the for loop, a warning appeared: "unreachable: Since the loop increment ix++; is unreachable, the loop body will never execute more than once." Therefore, I have made some simple refactoring to address these issues.
gcc/ChangeLog: * config/riscv/riscv-vsetvl.cc (bitmap_union_of_preds_with_entry): Refactor. Signed-off-by: Jin Ma <ji...@linux.alibaba.com> --- gcc/config/riscv/riscv-vsetvl.cc | 40 ++++++++++++++------------------ 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/gcc/config/riscv/riscv-vsetvl.cc b/gcc/config/riscv/riscv-vsetvl.cc index 4891b6c95e8..ffbe8986cec 100644 --- a/gcc/config/riscv/riscv-vsetvl.cc +++ b/gcc/config/riscv/riscv-vsetvl.cc @@ -100,31 +100,27 @@ using namespace riscv_vector; static void bitmap_union_of_preds_with_entry (sbitmap dst, sbitmap *src, basic_block b) { - unsigned int set_size = dst->size; - edge e; - unsigned ix; - - for (ix = 0; ix < EDGE_COUNT (b->preds); ix++) + /* Handle case with no predecessors (including ENTRY block). */ + if (EDGE_COUNT (b->preds) == 0) { - e = EDGE_PRED (b, ix); - bitmap_copy (dst, src[e->src->index]); - break; + bitmap_clear (dst); + return; } - if (ix == EDGE_COUNT (b->preds)) - bitmap_clear (dst); - else - for (ix++; ix < EDGE_COUNT (b->preds); ix++) - { - unsigned int i; - SBITMAP_ELT_TYPE *p, *r; - - e = EDGE_PRED (b, ix); - p = src[e->src->index]->elms; - r = dst->elms; - for (i = 0; i < set_size; i++) - *r++ |= *p++; - } + /* Initialize with first predecessor's bitmap. */ + edge first_pred = EDGE_PRED (b, 0); + bitmap_copy (dst, src[first_pred->src->index]); + + /* Union remaining predecessors' bitmaps. */ + for (unsigned ix = 1; ix < EDGE_COUNT (b->preds); ix++) + { + edge e = EDGE_PRED (b, ix); + const sbitmap pred_src = src[e->src->index]; + + /* Perform bitmap OR operation element-wise. */ + for (unsigned i = 0; i < dst->size; i++) + dst->elms[i] |= pred_src->elms[i]; + } } /* Compute the reaching definition in and out based on the gen and KILL -- 2.25.1