[llvm] [KnownBits] Speed up conflict handling in ForeachKnownBits in unit test. (PR #94943)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 10 02:19:34 PDT 2024


https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/94943

Exit early if known bits have a conflict. This gives me a ~15% speed up
when running this in my Release+Asserts build:

$ unittests/Support/SupportTests --gtest_filter=KnownBitsTest.*Exhaustive


>From 066f432ce7cacbd27cbc4552f85e05e38df1e4c4 Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Mon, 10 Jun 2024 10:10:33 +0100
Subject: [PATCH] [KnownBits] Speed up conflict handling in ForeachKnownBits in
 unit test.

Exit early if known bits have a conflict. This gives me a ~15% speed up
when running this in my Release+Asserts build:

$ unittests/Support/SupportTests --gtest_filter=KnownBitsTest.*Exhaustive
---
 llvm/unittests/Support/KnownBitsTest.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/llvm/unittests/Support/KnownBitsTest.h b/llvm/unittests/Support/KnownBitsTest.h
index 974051891d48e..807ce31381efb 100644
--- a/llvm/unittests/Support/KnownBitsTest.h
+++ b/llvm/unittests/Support/KnownBitsTest.h
@@ -38,6 +38,12 @@ void ForeachNumInKnownBits(const KnownBits &Known, FnTy Fn) {
   unsigned Max = 1u << Bits;
   unsigned Zero = Known.Zero.getZExtValue();
   unsigned One = Known.One.getZExtValue();
+
+  if (Zero & One) {
+    // Known has a conflict. No values will satisfy it.
+    return;
+  }
+
   for (unsigned N = 0; N < Max; ++N) {
     if ((N & Zero) == 0 && (~N & One) == 0)
       Fn(APInt(Bits, N));



More information about the llvm-commits mailing list