[PATCH] D140636: [Support] Fix what I think is an off by 1 bug in UnsignedDivisionByConstantInfo.

Sergei Barannikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 24 14:43:49 PST 2022


barannikov88 added a comment.

In D140636#4016127 <https://reviews.llvm.org/D140636#4016127>, @lebedev.ri wrote:

> Let me add some tests here.

In case that helps, I've tried a few bitwidth variants.
With LeadingZeros = 0, I get different magics iff the divisor has LSB and MSB ones and all other bits zeros. (I.e. 0b1000...0001 for any bitwidth.)
Example: APInt(8, 0x81).

With LeadingZeros != 0, the old algorithm asserts iff the divisor is a certain power of two. Examples:
 D = APInt(8, 0x80) and LeadingZeros = 1
 D = APInt(8, 0x40) and LeadingZeros = 2.
The fixed version does not crash and returns that seems to be correct values (can that be enough for a unittest?)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140636/new/

https://reviews.llvm.org/D140636



More information about the llvm-commits mailing list