forked from OSchip/llvm-project
[InstCombine] don't form select from logic ops if it's unlikely that we'll eliminate any ops
llvm-svn: 274926
This commit is contained in:
parent
297a0e67b6
commit
f4a08ede03
|
@ -2222,23 +2222,28 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
|
|||
}
|
||||
}
|
||||
|
||||
// (Cond & C) | (~Cond & D) -> Cond ? C : D, and commuted variants.
|
||||
if (Value *V = matchSelectFromAndOr(A, C, B, D, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(A, C, D, B, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(C, A, B, D, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(C, A, D, B, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(B, D, A, C, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(B, D, C, A, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(D, B, A, C, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(D, B, C, A, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
// Don't try to form a select if it's unlikely that we'll get rid of at
|
||||
// least one of the operands. A select is generally more expensive than the
|
||||
// 'or' that it is replacing.
|
||||
if (Op0->hasOneUse() || Op1->hasOneUse()) {
|
||||
// (Cond & C) | (~Cond & D) -> Cond ? C : D, and commuted variants.
|
||||
if (Value *V = matchSelectFromAndOr(A, C, B, D, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(A, C, D, B, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(C, A, B, D, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(C, A, D, B, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(B, D, A, C, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(B, D, C, A, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(D, B, A, C, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
if (Value *V = matchSelectFromAndOr(D, B, C, A, *Builder))
|
||||
return replaceInstUsesWith(I, V);
|
||||
}
|
||||
|
||||
// ((A&~B)|(~A&B)) -> A^B
|
||||
if ((match(C, m_Not(m_Specific(D))) &&
|
||||
|
|
|
@ -300,10 +300,8 @@ define i1 @bools_multi_uses2(i1 %a, i1 %b, i1 %c) {
|
|||
; CHECK-NEXT: [[NOT:%.*]] = xor i1 %c, true
|
||||
; CHECK-NEXT: [[AND1:%.*]] = and i1 [[NOT]], %a
|
||||
; CHECK-NEXT: [[AND2:%.*]] = and i1 %c, %b
|
||||
; CHECK-NEXT: [[TMP1:%.*]] = select i1 %c, i1 %b, i1 %a
|
||||
; CHECK-NEXT: [[ADD:%.*]] = xor i1 [[AND1]], [[AND2]]
|
||||
; CHECK-NEXT: [[AND3:%.*]] = and i1 [[TMP1]], [[ADD]]
|
||||
; CHECK-NEXT: ret i1 [[AND3]]
|
||||
; CHECK-NEXT: ret i1 [[ADD]]
|
||||
;
|
||||
%not = xor i1 %c, -1
|
||||
%and1 = and i1 %not, %a
|
||||
|
|
Loading…
Reference in New Issue