[InstCombine] check for one-use before turning simple logic op into a select

llvm-svn: 274891
This commit is contained in:
Sanjay Patel 2016-07-08 17:26:47 +00:00
parent 068a8054ae
commit 1b6b824548
2 changed files with 3 additions and 5 deletions

View File

@ -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);

View File

@ -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]]
;