ComputeNumSignBits returns incorrect results for srem instructions.
This change fixes the issue and adds a test case.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/Analysis/ValueTracking.cpp | ||
---|---|---|
1937 ↗ | (On Diff #22626) | Blank comment line. |
1941 ↗ | (On Diff #22626) | Is this ever different from Denominator.ceilLogBase2()? |
test/Analysis/ValueTracking/pr230011.ll | ||
1 ↗ | (On Diff #22626) | File name is off "pr230011.ll" should be "pr23011.ll". Also, if this is a bug in value tracking, isn't there a more direct way to observe it than this? Maybe just srem + and and then opt -instsimplify? |
lib/Analysis/ValueTracking.cpp | ||
---|---|---|
1937 ↗ | (On Diff #22626) | Will fix. |
1941 ↗ | (On Diff #22626) | The only case where this differs from TyBits - ceilLogBase2 is when Denominator = 1 -- TyBits - ceilLogBase2 will correctly be TyBits in that case (i.e. all bits are sign bits) but the current version of the code will return 0 (i.e. no bits are sign bits). I noticed this just now, and it was not intentional. I can think of two ways to fix this:
I'd prefer doing the latter. WDYT? |
test/Analysis/ValueTracking/pr230011.ll | ||
1 ↗ | (On Diff #22626) | Yes. I think I'll also switch out the constant-foldable instruction with something like srem %foo, 3. |
Nick, Sanjoy,
I am sorry for the bug. Thanks for catching and fixing it. One easy way to write a testcase is to rely on the 'overflow' optimizations in instcombine. See the function overflow_mod_mul in Transforms/InstCombine/intrinsics.ll.
-Nadav
lib/Analysis/ValueTracking.cpp | ||
---|---|---|
1941 ↗ | (On Diff #22626) | I have a weak preference to keep the comment explaining it as it does, then to use ceilLogBase2 in the implementation. I like code reuse and don't think Denominator==1 should ever make it this far so I'd rather not special case it, but either way is just fine with me. |
Address review:
- use ceilLogBase2
- fix test case file name
- test case to use @llvm.smul.with.overflow.i8