[llvm] r299658 - [InstCombine] Fix a case where we weren't checking that an instruction had a single use resulting in extra instructions being created.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 6 09:42:47 PDT 2017


Author: ctopper
Date: Thu Apr  6 11:42:46 2017
New Revision: 299658

URL: http://llvm.org/viewvc/llvm-project?rev=299658&view=rev
Log:
[InstCombine] Fix a case where we weren't checking that an instruction had a single use resulting in extra instructions being created.

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=299658&r1=299657&r2=299658&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp Thu Apr  6 11:42:46 2017
@@ -1332,18 +1332,21 @@ Instruction *InstCombiner::visitAnd(Bina
         // ((A & N) + B) & AndRHS -> (A + B) & AndRHS iff N&AndRHS == AndRHS.
         // ((A | N) + B) & AndRHS -> (A + B) & AndRHS iff N&AndRHS == 0
         // ((A ^ N) + B) & AndRHS -> (A + B) & AndRHS iff N&AndRHS == 0
-        if (Value *V = FoldLogicalPlusAnd(Op0LHS, Op0RHS, AndRHS, false, I))
-          return BinaryOperator::CreateAnd(V, AndRHS);
-        if (Value *V = FoldLogicalPlusAnd(Op0RHS, Op0LHS, AndRHS, false, I))
-          return BinaryOperator::CreateAnd(V, AndRHS);  // Add commutes
+        if (Op0I->hasOneUse()) {
+          if (Value *V = FoldLogicalPlusAnd(Op0LHS, Op0RHS, AndRHS, false, I))
+            return BinaryOperator::CreateAnd(V, AndRHS);
+          if (Value *V = FoldLogicalPlusAnd(Op0RHS, Op0LHS, AndRHS, false, I))
+            return BinaryOperator::CreateAnd(V, AndRHS);  // Add commutes
+        }
         break;
 
       case Instruction::Sub:
         // ((A & N) - B) & AndRHS -> (A - B) & AndRHS iff N&AndRHS == AndRHS.
         // ((A | N) - B) & AndRHS -> (A - B) & AndRHS iff N&AndRHS == 0
         // ((A ^ N) - B) & AndRHS -> (A - B) & AndRHS iff N&AndRHS == 0
-        if (Value *V = FoldLogicalPlusAnd(Op0LHS, Op0RHS, AndRHS, true, I))
-          return BinaryOperator::CreateAnd(V, AndRHS);
+        if (Op0I->hasOneUse())
+          if (Value *V = FoldLogicalPlusAnd(Op0LHS, Op0RHS, AndRHS, true, I))
+            return BinaryOperator::CreateAnd(V, AndRHS);
 
         // -x & 1 -> x & 1
         if (AndRHSMask == 1 && match(Op0LHS, m_Zero()))




More information about the llvm-commits mailing list