Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KnownBits] Speed up conflict handling in ForeachKnownBits in unit test. #94943

Merged
merged 1 commit into from
Jun 10, 2024

Conversation

jayfoad
Copy link
Contributor

@jayfoad jayfoad commented Jun 10, 2024

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

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
@llvmbot
Copy link
Collaborator

llvmbot commented Jun 10, 2024

@llvm/pr-subscribers-llvm-support

Author: Jay Foad (jayfoad)

Changes

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

@jayfoad jayfoad merged commit ecb9d94 into llvm:main Jun 10, 2024
7 of 8 checks passed
@jayfoad jayfoad deleted the foreachnuminknownbits-conflict branch June 10, 2024 10:03
@HerrCai0907 HerrCai0907 mentioned this pull request Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants