[llvm] 062415d - [InstCombine] improve description of fold and add TODO; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 13 07:35:00 PST 2023


Author: Sanjay Patel
Date: 2023-01-13T10:34:55-05:00
New Revision: 062415d3c8c1f63697583f4cb98c0892982ceac6

URL: https://github.com/llvm/llvm-project/commit/062415d3c8c1f63697583f4cb98c0892982ceac6
DIFF: https://github.com/llvm/llvm-project/commit/062415d3c8c1f63697583f4cb98c0892982ceac6.diff

LOG: [InstCombine] improve description of fold and add TODO; NFC

D58633

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index b76be357f3168..754b791aff87e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -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.


        


More information about the llvm-commits mailing list