[PATCH] D140733: [InstSimplify] fold exact divide to poison if it is known to not divide evenly

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 29 05:32:29 PST 2022


spatel marked 2 inline comments as done.
spatel added a comment.

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

> Do we do this for right-shifts already?
> If not, might be easier to start with that.

There is a variation on this theme for shifts (pasted code below), so I'll put a TODO on that.
I saw the missed division first, and I think we'd be more likely to spot bugs with a botched div if this manages to uncover any broken transforms.

  // The low bit cannot be shifted out of an exact shift if it is set.
  if (isExact) {
    KnownBits Op0Known =
        computeKnownBits(Op0, Q.DL, /*Depth=*/0, Q.AC, Q.CxtI, Q.DT);
    if (Op0Known.One[0])
      return Op0;
  }



================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:1160
+    KnownBits KnownOp0 = computeKnownBits(Op0, Q.DL, 0, Q.AC, Q.CxtI, Q.DT);
+    if (KnownOp0.countMaxTrailingZeros() < DivC->countTrailingZeros())
+      return PoisonValue::get(Op0->getType());
----------------
lebedev.ri wrote:
> I think this is a better proof:
> ```
> https://alive2.llvm.org/ce/z/zCjKM7
> But not: https://alive2.llvm.org/ce/z/-tz_RK
> ```
Do the extra function args just allow showing the TZ values/bounds more easily, or is there another benefit from writing it like that?


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

https://reviews.llvm.org/D140733



More information about the llvm-commits mailing list