Added InstCombine for "select cond, ~cond, x" type patterns

These can be reduced to "~cond & x" or "~cond | x"

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146624 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Pete Cooper 2011-12-15 00:56:45 +00:00
parent 4e0adfa7f7
commit 4e5a1ab10b
2 changed files with 27 additions and 0 deletions

View File

@ -682,6 +682,13 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
return BinaryOperator::CreateOr(CondVal, FalseVal);
else if (CondVal == FalseVal)
return BinaryOperator::CreateAnd(CondVal, TrueVal);
// select a, ~a, b -> (~a)&b
// select a, b, ~a -> (~a)|b
if (match(TrueVal, m_Not(m_Specific(CondVal))))
return BinaryOperator::CreateAnd(TrueVal, FalseVal);
else if (match(FalseVal, m_Not(m_Specific(CondVal))))
return BinaryOperator::CreateOr(TrueVal, FalseVal);
}
// Selecting between two integer constants?

View File

@ -809,3 +809,23 @@ define i32 @test61(i32* %ptr) {
; CHECK: @test61
; CHECK: ret i32 10
}
define i1 @test62(i1 %A, i1 %B) {
%not = xor i1 %A, true
%C = select i1 %A, i1 %not, i1 %B
ret i1 %C
; CHECK: @test62
; CHECK: %not = xor i1 %A, true
; CHECK: %C = and i1 %not, %B
; CHECK: ret i1 %C
}
define i1 @test63(i1 %A, i1 %B) {
%not = xor i1 %A, true
%C = select i1 %A, i1 %B, i1 %not
ret i1 %C
; CHECK: @test63
; CHECK: %not = xor i1 %A, true
; CHECK: %C = or i1 %B, %not
; CHECK: ret i1 %C
}