[llvm] [KnownBits] Improve minimum denominator bounds for sdiv (PR #227264)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 4 01:02:56 PDT 2026
anandkvinu wrote:
@ZERICO2005 this is the example i did in unit test:
TEST(KnownBitsTest, NonZeroDenomSDiv) {
KnownBits Num = KnownBits::makeConstant(APInt(4, -8, true));
KnownBits Denom(4);
// Denom = 0b0?00.
Denom.Zero.setBit(3);
//Denom.Zero.setBit(2);
Denom.Zero.setBit(1);
Denom.Zero.setBit(0);
KnownBits Result = KnownBits::sdiv(Num, Denom);
KnownBits Answer = KnownBits::makeConstant(APInt(4, -2, true));
EXPECT_EQ(Result, Answer);
}
and this was the output of the test:
/home/user/Documents/anand/llvm23/llvm-project/llvm/unittests/Support/KnownBitsTest.cpp:710: Failure
Expected equality of these values:
Result
Which is: 111?
Answer
Which is: 1110
[ FAILED ] KnownBitsTest.NonZeroDenomSDiv (0 ms)
[----------] 1 test from KnownBitsTest (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] KnownBitsTest.NonZeroDenomSDiv
1 FAILED TEST
as you can see here the value stored in result is 111? and not 1110 . if i test it with the Answer.One.setHighBits(3);
instead of Answer = KnownBits::makeConstant(APInt(4, -2, true));
the test passes!! its checking the setbits.
is this what you meant when you said "where you would check that the known bits of the return value are 0b111??? or etc for example"???
let me know? thanks.
https://github.com/llvm/llvm-project/pull/227264
More information about the llvm-commits
mailing list