[PATCH] D114279: [InstSimplify] Fold X {lshr,udiv} C <u X --> true for nonzero X, non-identity C

Erik Desjardins via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 23 16:45:24 PST 2021


erikdesjardins marked an inline comment as not done.
erikdesjardins added inline comments.


================
Comment at: llvm/lib/Analysis/InstructionSimplify.cpp:2952
+  // x udiv C <u x --> true for C > 1.
+  // TODO: allow non-constant shift amount/divisor
+  const APInt *C;
----------------
spatel wrote:
> Is that TODO feasible? The lshr half could use isKnownNonZero, but how would we deal with ">1" for udiv?
I think something like

  KnownBits Known = computeKnownBits(Divisor, ...);
  if (KnownBits::ne(Known, KnownBits::makeConstant(1)))

would technically work.

I don't know if this would help much in practice though; I can remove "divisor" from the comment if you prefer.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D114279



More information about the llvm-commits mailing list