[PATCH] D69387: [ConstantRange] Add toKnownBits() method

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 26 01:24:20 PDT 2019


lebedev.ri marked an inline comment as done.
lebedev.ri added inline comments.


================
Comment at: llvm/lib/IR/ConstantRange.cpp:117
+  Known.One.clearLowBits(*Bit);
+  Known.Zero.clearLowBits(1 + *Bit);
+
----------------
lebedev.ri wrote:
> nikic wrote:
> > Why is it necessary to clear one more bit in the Zero case?
> Technically, it's the other way around, we can/need to clean exactly `1 + *Bit` low bits from them,
> but in the case of `Known.One`, the `1 + *Bit` bit is already always unset (because i used `getUnsignedMin()`),
> so it doesn't require unsetting.
> 
To spell this out further:
`HighestTransientBit` is the most significant bit that is different between `getUnsignedMin()` and `getUnsignedMax()`.
All bits (if any) that are higher/more significant/more MSB are all identical.
Which means, since `getUnsignedMin()` (which is less than `getUnsignedMax()`) is used as baseline reference
for `Known.One` and `Known.Zero`, the `HighestTransientBit`'th bit is *not* One, it is Zero.
So we only need to unset the Zero knowledge about it. But sure, we could unset both the One and Zero knowledge,
but that won't ever matter since this algo already results in precise match.

Let me know if that did/didn't explain it.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D69387





More information about the llvm-commits mailing list