[llvm] [BOLT][NFC] Simplify successor check (PR #91980)

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


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

I found the logic here confusing, the expression is over-parenthesized, and IMHO `boolean ? true-case : false-case` is clearer than `(boolean && true-case) || (!boolean && false-case)`.

>From b154477b3c1a4178e98017718c8f0f3e116f2ac4 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <nathan at acm.org>
Date: Mon, 13 May 2024 08:04:20 -0400
Subject: [PATCH] [BOLT][NFC] Simplify successor check

---
 bolt/lib/Core/BinaryBasicBlock.cpp | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/bolt/lib/Core/BinaryBasicBlock.cpp b/bolt/lib/Core/BinaryBasicBlock.cpp
index 4a83fece0e43d..a4b9a7f558cd8 100644
--- a/bolt/lib/Core/BinaryBasicBlock.cpp
+++ b/bolt/lib/Core/BinaryBasicBlock.cpp
@@ -131,11 +131,10 @@ bool BinaryBasicBlock::validateSuccessorInvariants() {
         break;
       }
       case 2:
-        Valid = (CondBranch &&
-                 (TBB == getConditionalSuccessor(true)->getLabel() &&
-                  ((!UncondBranch && !FBB) ||
-                   (UncondBranch &&
-                    FBB == getConditionalSuccessor(false)->getLabel()))));
+        Valid =
+            CondBranch && TBB == getConditionalSuccessor(true)->getLabel() &&
+            (UncondBranch ? FBB == getConditionalSuccessor(false)->getLabel()
+                          : !FBB);
         break;
       }
     }



More information about the llvm-commits mailing list