From 066f432ce7cacbd27cbc4552f85e05e38df1e4c4 Mon Sep 17 00:00:00 2001 From: Jay Foad 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 974051891d48e7..807ce31381efbf 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));