[llvm] ecb9d94 - [KnownBits] Speed up conflict handling in ForeachKnownBits in unit test. (#94943)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 03:03:22 PDT 2024
Author: Jay Foad
Date: 2024-06-10T11:03:18+01:00
New Revision: ecb9d94a8bfb07591fdfcf3418c5cfafcad5a13d
URL: https://github.com/llvm/llvm-project/commit/ecb9d94a8bfb07591fdfcf3418c5cfafcad5a13d
DIFF: https://github.com/llvm/llvm-project/commit/ecb9d94a8bfb07591fdfcf3418c5cfafcad5a13d.diff
LOG: [KnownBits] Speed up conflict handling in ForeachKnownBits in unit test. (#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
Added:
Modified:
llvm/unittests/Support/KnownBitsTest.h
Removed:
################################################################################
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