diff options
author | Craig Topper <craig.topper@gmail.com> | 2017-04-06 16:42:46 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2017-04-06 16:42:46 +0000 |
commit | 3fc1225c1851a2511bade654751e1ed42dda3653 (patch) | |
tree | a8fc1698e08b47b292a2d20ae646f36daec47774 /llvm/lib | |
parent | edaf907d36a9d4a3e8bdc93135b43758a14bbce4 (diff) | |
download | bcm5719-llvm-3fc1225c1851a2511bade654751e1ed42dda3653.tar.gz bcm5719-llvm-3fc1225c1851a2511bade654751e1ed42dda3653.zip |
[InstCombine] Fix a case where we weren't checking that an instruction had a single use resulting in extra instructions being created.
llvm-svn: 299658
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index e764033dd2e..1761fcf455b 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -1332,18 +1332,21 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) { // ((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())) |