[llvm] r300222 - [InstCombine] use similar ops for related folds; NFCI

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 13 10:36:24 PDT 2017


Author: spatel
Date: Thu Apr 13 12:36:24 2017
New Revision: 300222

URL: http://llvm.org/viewvc/llvm-project?rev=300222&view=rev
Log:
[InstCombine] use similar ops for related folds; NFCI

It's less efficient to produce 'ule' than 'ult' since we know we're going to
canonicalize to 'ult', but we shouldn't have duplicated code for these folds.

As a trade-off, this was a pretty terrible way to make a '2'. :)
       if (LHSC == SubOne(RHSC)) 
         AddC = ConstantExpr::getSub(AddOne(RHSC), LHSC);

The next steps are to share the code to fix PR32524 and add the missing 'and'
fold that was left out when PR14708 was fixed:
https://bugs.llvm.org/show_bug.cgi?id=14708


Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp?rev=300222&r1=300221&r2=300222&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Thu Apr 13 12:36:24 2017
@@ -881,11 +881,11 @@ Value *InstCombiner::FoldAndOfICmps(ICmp
       // zero.
       if (LHSC->getValue() == 0 && RHSC->getValue().isAllOnesValue())
         std::swap(LHSC, RHSC);
-      if (LHSC == SubOne(RHSC)) { // (X != 13 & X != 14) -> X-13 >u 1
-        Constant *AddC = ConstantExpr::getNeg(LHSC);
-        Value *Add = Builder->CreateAdd(LHS0, AddC, LHS0->getName() + ".off");
-        return Builder->CreateICmpUGT(Add, ConstantInt::get(Add->getType(), 1),
-                                      LHS0->getName() + ".cmp");
+      if (LHSC == SubOne(RHSC)) {
+        // (X != 13 & X != 14) -> X-13 >u 1
+        // An 'add' is the canonical IR form, so favor that over a 'sub'.
+        Value *Add = Builder->CreateAdd(LHS0, ConstantExpr::getNeg(LHSC));
+        return Builder->CreateICmpUGT(Add, ConstantInt::get(Add->getType(), 1));
       }
       break; // (X != 13 & X != 15) -> no change
     }
@@ -1786,11 +1786,10 @@ Value *InstCombiner::FoldOrOfICmps(ICmpI
       }
 
       if (LHSC == SubOne(RHSC)) {
-        // (X == 13 | X == 14) -> X-13 <u 2
-        Constant *AddC = ConstantExpr::getNeg(LHSC);
-        Value *Add = Builder->CreateAdd(LHS0, AddC, LHS0->getName() + ".off");
-        AddC = ConstantExpr::getSub(AddOne(RHSC), LHSC);
-        return Builder->CreateICmpULT(Add, AddC);
+        // (X == 13 | X == 14) -> X-13 <=u 1
+        // An 'add' is the canonical IR form, so favor that over a 'sub'.
+        Value *Add = Builder->CreateAdd(LHS0, ConstantExpr::getNeg(LHSC));
+        return Builder->CreateICmpULE(Add, ConstantInt::get(Add->getType(), 1));
       }
 
       break;                 // (X == 13 | X == 15) -> no change




More information about the llvm-commits mailing list