[llvm] [BOLT][NFC] Simplify CFG validation (PR #91977)

Nathan Sidwell via llvm-commits llvm-commits at lists.llvm.org
Mon May 13 08:08:10 PDT 2024


https://github.com/urnathan created https://github.com/llvm/llvm-project/pull/91977

I noticed this `Valid` local had one use, whereas the rest of the function just directly returned false on failure

>From ca89711b441a3775b11f5fc2ea836f3c8398f0eb Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan at acm.org>
Date: Mon, 13 May 2024 07:36:47 -0400
Subject: [PATCH] [BOLT][NFC] Simplify CFG validation

---
 bolt/lib/Core/BinaryFunction.cpp | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp
index de34421ebeb08..4f44ba0d970c0 100644
--- a/bolt/lib/Core/BinaryFunction.cpp
+++ b/bolt/lib/Core/BinaryFunction.cpp
@@ -3252,12 +3252,9 @@ bool BinaryFunction::validateCFG() const {
   if (CurrentState == State::CFG_Finalized)
     return true;
 
-  bool Valid = true;
   for (BinaryBasicBlock *BB : BasicBlocks)
-    Valid &= BB->validateSuccessorInvariants();
-
-  if (!Valid)
-    return Valid;
+    if (!BB->validateSuccessorInvariants())
+      return false;
 
   // Make sure all blocks in CFG are valid.
   auto validateBlock = [this](const BinaryBasicBlock *BB, StringRef Desc) {
@@ -3326,7 +3323,7 @@ bool BinaryFunction::validateCFG() const {
     }
   }
 
-  return Valid;
+  return true;
 }
 
 void BinaryFunction::fixBranches() {



More information about the llvm-commits mailing list