[llvm] [KnownBits] Speed up ForeachKnownBits in unit test. NFC. (PR #94939)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 10 01:55:21 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Jay Foad (jayfoad)
<details>
<summary>Changes</summary>
Use fast unsigned arithmetic before constructing an APInt. This gives
me a ~2x 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/94939.diff
1 Files Affected:
- (modified) llvm/unittests/Support/KnownBitsTest.h (+6-6)
``````````diff
diff --git a/llvm/unittests/Support/KnownBitsTest.h b/llvm/unittests/Support/KnownBitsTest.h
index 556da2b9ecdad..974051891d48e 100644
--- a/llvm/unittests/Support/KnownBitsTest.h
+++ b/llvm/unittests/Support/KnownBitsTest.h
@@ -34,13 +34,13 @@ template <typename FnTy> void ForeachKnownBits(unsigned Bits, FnTy Fn) {
template <typename FnTy>
void ForeachNumInKnownBits(const KnownBits &Known, FnTy Fn) {
unsigned Bits = Known.getBitWidth();
- unsigned Max = 1 << Bits;
+ assert(Bits < 32);
+ unsigned Max = 1u << Bits;
+ unsigned Zero = Known.Zero.getZExtValue();
+ unsigned One = Known.One.getZExtValue();
for (unsigned N = 0; N < Max; ++N) {
- APInt Num(Bits, N);
- if ((Num & Known.Zero) != 0 || (~Num & Known.One) != 0)
- continue;
-
- Fn(Num);
+ if ((N & Zero) == 0 && (~N & One) == 0)
+ Fn(APInt(Bits, N));
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/94939
More information about the llvm-commits
mailing list