]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
RISC-V: Refactor the function bitmap_union_of_preds_with_entry
authorJin Ma <jinma@linux.alibaba.com>
Sat, 28 Jun 2025 11:55:00 +0000 (19:55 +0800)
committerJin Ma <jinma@linux.alibaba.com>
Mon, 30 Jun 2025 02:57:50 +0000 (10:57 +0800)
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 <jinma@linux.alibaba.com>
gcc/config/riscv/riscv-vsetvl.cc

index 4891b6c95e85518706147f5c9824302946b5ced5..4fe0ae6d97b70c3d476373489caa86e6deb8e455 100644 (file)
@@ -100,31 +100,28 @@ 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++;
-      }
+  edge e;
+  edge_iterator ei;
+  /* Union remaining predecessors' bitmaps.  */
+  FOR_EACH_EDGE (e, ei, b->preds)
+    {
+      /* Initialize with first predecessor's bitmap.  */
+      if (ei.index == 0)
+       {
+         bitmap_copy (dst, src[e->src->index]);
+         continue;
+       }
+
+      /* Perform bitmap OR operation element-wise.  */
+      bitmap_ior (dst, dst, src[e->src->index]);
+    }
 }
 
 /* Compute the reaching definition in and out based on the gen and KILL