[PATCH] D150100: [KnownBits] Improve implementation of `KnownBits::abs`
Noah Goldstein via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 8 17:20:09 PDT 2023
goldstein.w.n added inline comments.
================
Comment at: llvm/lib/Support/KnownBits.cpp:423
+ KnownBits KnownNeg = computeForAddSub(
+ /*Add*/ false, /*NSW*/ false, Zero, *this);
+
----------------
nikic wrote:
> You can pass IntMinIsPoison to the NSW argument.
> You can pass IntMinIsPoison to the NSW argument.
Can we? The `0-Negative_X` is positive unless `Negative_X == INT_MIN` so if `IntMinIsPoison` we can't set `NSW`. Also would do slightly better and just do `KnownAbs.isNonNegative()` because it uses the `IntMinIsPoison` condition (and others) to try and set output sign.
But either way, since `KnownAbs` already has logic for setting output sign and we combine our result from negation with `KnownAbs` its kind of a non-issue.
================
Comment at: llvm/lib/Support/KnownBits.cpp:426
+ // NB: KnownAbs is not always a subset of KnownNeg so we want to get input
+ // from both.
+ KnownAbs.One |= KnownNeg.One;
----------------
nikic wrote:
> Under which circumstance is KnownAbs better? Seems fishy.
> Under which circumstance is KnownAbs better? Seems fishy.
The output sign at the very least. But when testing (even when I was getting the right sign from the `computeForAddSub` `assert(KnownAbs.Zero.isSubsetOf(KnownNeg.Zero) && KnownAbs.isSubsetOf(KnownNeg.One))` was failing on the exhaustive tests.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150100/new/
https://reviews.llvm.org/D150100
More information about the llvm-commits
mailing list