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

via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 10 02:20:06 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Jay Foad (jayfoad)

<details>
<summary>Changes</summary>

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


---
Full diff: https://github.com/llvm/llvm-project/pull/94943.diff


1 Files Affected:

- (modified) llvm/unittests/Support/KnownBitsTest.h (+6) 


``````````diff
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));

``````````

</details>


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


More information about the llvm-commits mailing list