[PATCH] D125264: [ConstraintElimination] Simplify ssub(a, b) if a s>=b && a s>=0.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed May 11 13:25:37 PDT 2022


fhahn marked an inline comment as done.
fhahn added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/ConstraintElimination.cpp:537-538
+  if (II->getIntrinsicID() == Intrinsic::ssub_with_overflow) {
+    // If A s>= B && A s>= 0, ssub.with.overflow(a, b) should not overflow and
+    // can be simplified to a regular sub.
+    Value *A = II->getArgOperand(0);
----------------
spatel wrote:
> This pre-condition is not correct - if A is 0 and B is SMIN for a given width, that overflows.
> 
> Double-check to make sure I got the right pattern, but we should have a test like this:
> https://alive2.llvm.org/ce/z/t9G3TQ
Thanks, this needs to check if B >= 0, which also implies A >= 0. I added additional tests in 1911843c3126 based on the shared alive2 code (I think the one you shared had different compares for `%c.2` in `@src` and `@tgt`, so the verification failure was about that, here's a slightly updated one: https://alive2.llvm.org/ce/z/L_K648)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D125264



More information about the llvm-commits mailing list