diff options
| author | Sanjay Patel <spatel@rotateright.com> | 2016-07-08 17:26:47 +0000 |
|---|---|---|
| committer | Sanjay Patel <spatel@rotateright.com> | 2016-07-08 17:26:47 +0000 |
| commit | 1b6b82454883419852fc3aafc94e30dcfe5e4671 (patch) | |
| tree | a1ca9104bd54e6b30670464f8d1cc78c1938ba4b /llvm | |
| parent | 068a8054aed30c587619bec7e4d25fb11d9a9834 (diff) | |
| download | bcm5719-llvm-1b6b82454883419852fc3aafc94e30dcfe5e4671.tar.gz bcm5719-llvm-1b6b82454883419852fc3aafc94e30dcfe5e4671.zip | |
[InstCombine] check for one-use before turning simple logic op into a select
llvm-svn: 274891
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 4 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstCombine/or.ll | 4 |
2 files changed, 3 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index f6ec03b9721..eadf0bf67a4 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2394,10 +2394,10 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { return CastedOr; // or(sext(A), B) / or(B, sext(A)) --> A ? -1 : B, where A is i1 or <N x i1>. - if (match(Op0, m_SExt(m_Value(A))) && + if (match(Op0, m_OneUse(m_SExt(m_Value(A)))) && A->getType()->getScalarType()->isIntegerTy(1)) return SelectInst::Create(A, ConstantInt::getSigned(I.getType(), -1), Op1); - if (match(Op1, m_SExt(m_Value(A))) && + if (match(Op1, m_OneUse(m_SExt(m_Value(A)))) && A->getType()->getScalarType()->isIntegerTy(1)) return SelectInst::Create(A, ConstantInt::getSigned(I.getType(), -1), Op0); diff --git a/llvm/test/Transforms/InstCombine/or.ll b/llvm/test/Transforms/InstCombine/or.ll index 6ecabeea229..53cb48809fc 100644 --- a/llvm/test/Transforms/InstCombine/or.ll +++ b/llvm/test/Transforms/InstCombine/or.ll @@ -445,12 +445,10 @@ define i32 @orsext_to_sel_swap(i32 %x, i1 %y) { ret i32 %or } -; FIXME: Don't replace an 'or' with a select unless it allows further simplification. - define i32 @orsext_to_sel_multi_use(i32 %x, i1 %y) { ; CHECK-LABEL: @orsext_to_sel_multi_use( ; CHECK-NEXT: [[SEXT:%.*]] = sext i1 %y to i32 -; CHECK-NEXT: [[OR:%.*]] = select i1 %y, i32 -1, i32 %x +; CHECK-NEXT: [[OR:%.*]] = or i32 [[SEXT]], %x ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[SEXT]], [[OR]] ; CHECK-NEXT: ret i32 [[ADD]] ; |

