[PATCH] D150100: [KnownBits] Improve implementation of `KnownBits::abs`

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 9 04:06:17 PDT 2023


nikic added inline comments.


================
Comment at: llvm/lib/Support/KnownBits.cpp:423
+    KnownBits KnownNeg = computeForAddSub(
+        /*Add*/ false, /*NSW*/ false, Zero, *this);
+
----------------
goldstein.w.n wrote:
> 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.
I don't understand. The only value for which `0-X` wraps is INT_MIN, which is exactly what the IntMinIsPoison flag controls. The entire purpose of that flag is to allow an `nsw` assumption on the negation.


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