[llvm] [InstCombine] Infer sub nuw from dominating conditions (PR #100164)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 24 02:54:19 PDT 2024


================
@@ -2175,7 +2175,10 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
       Changed = true;
       I.setHasNoSignedWrap(true);
     }
-    if (!I.hasNoUnsignedWrap() && willNotOverflowUnsignedSub(Op0, Op1, I)) {
+    if (!I.hasNoUnsignedWrap() &&
+        (willNotOverflowUnsignedSub(Op0, Op1, I) ||
+         isImpliedByDomCondition(ICmpInst::ICMP_UGE, Op0, Op1, &I, DL)
----------------
nikic wrote:

This check already exists inside computeOverflowForUnsignedSub, but is currently only enabled for usub_with_overflow. It would probably make more sense to remove the pre-condition there rather than repeat it here?

https://github.com/llvm/llvm-project/pull/100164


More information about the llvm-commits mailing list