[InstCombine] improve description of fold and add TODO; NFC
authorSanjay Patel <spatel@rotateright.com>
Fri, 13 Jan 2023 13:59:21 +0000 (08:59 -0500)
committerSanjay Patel <spatel@rotateright.com>
Fri, 13 Jan 2023 15:34:55 +0000 (10:34 -0500)
D58633

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

index b76be35..754b791 100644 (file)
@@ -3157,10 +3157,12 @@ Instruction *InstCombinerImpl::foldICmpBinOpEqualityWithConstant(
     }
     break;
   case Instruction::Add: {
-    // Replace ((add A, B) != C) with (A != C-B) if B & C are constants.
-    if (Constant *BOC = dyn_cast<Constant>(BOp1)) {
+    // (A + C2) == C --> A == (C - C2)
+    // (A + C2) != C --> A != (C - C2)
+    // TODO: Remove the one-use limitation? See discussion in D58633.
+    if (Constant *C2 = dyn_cast<Constant>(BOp1)) {
       if (BO->hasOneUse())
-        return new ICmpInst(Pred, BOp0, ConstantExpr::getSub(RHS, BOC));
+        return new ICmpInst(Pred, BOp0, ConstantExpr::getSub(RHS, C2));
     } else if (C.isZero()) {
       // Replace ((add A, B) != 0) with (A != -B) if A or B is
       // efficiently invertible, or if the add has just this one use.