diff options
author | Pete Cooper <peter_cooper@apple.com> | 2011-12-15 00:56:45 +0000 |
---|---|---|
committer | Pete Cooper <peter_cooper@apple.com> | 2011-12-15 00:56:45 +0000 |
commit | 4e5a1ab10b62b7ca842afd0e99ac982153f217fb (patch) | |
tree | 6d1ec10d4f0722223378a44a48bf330829337f42 | |
parent | 4e0adfa7f7fa5617a7a06028cdad0e4a50cac22a (diff) | |
download | external_llvm-4e5a1ab10b62b7ca842afd0e99ac982153f217fb.zip external_llvm-4e5a1ab10b62b7ca842afd0e99ac982153f217fb.tar.gz external_llvm-4e5a1ab10b62b7ca842afd0e99ac982153f217fb.tar.bz2 |
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
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineSelect.cpp | 7 | ||||
-rw-r--r-- | test/Transforms/InstCombine/select.ll | 20 |
2 files changed, 27 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineSelect.cpp b/lib/Transforms/InstCombine/InstCombineSelect.cpp index 84f80f0..f1ea8ea 100644 --- a/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -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? diff --git a/test/Transforms/InstCombine/select.ll b/test/Transforms/InstCombine/select.ll index 4661561..4baae26 100644 --- a/test/Transforms/InstCombine/select.ll +++ b/test/Transforms/InstCombine/select.ll @@ -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 +} |