diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2011-04-14 22:41:27 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2011-04-14 22:41:27 +0000 |
commit | 2395626605b7844fef6a87bfb666f8be40e3afa6 (patch) | |
tree | d03727331913583b5f725050ba493b641e958bf9 /llvm/lib/Transforms/InstCombine | |
parent | 40965fa78a991c41527a2bed0d8c5c822e3d5afe (diff) | |
download | bcm5719-llvm-2395626605b7844fef6a87bfb666f8be40e3afa6.tar.gz bcm5719-llvm-2395626605b7844fef6a87bfb666f8be40e3afa6.zip |
Add an instcombine for constructs like a | -(b != c); a select is more
canonical, and generally leads to better code. Found while looking at
an article about saturating arithmetic.
llvm-svn: 129545
Diffstat (limited to 'llvm/lib/Transforms/InstCombine')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 1cb18e12eef..6cf405328a3 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -2003,7 +2003,14 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) { } } } - + + // or(sext(A), B) -> A ? -1 : B where A is an i1 + // or(A, sext(B)) -> B ? -1 : A where B is an i1 + if (match(Op0, m_SExt(m_Value(A))) && A->getType()->isIntegerTy(1)) + return SelectInst::Create(A, ConstantInt::getSigned(I.getType(), -1), Op1); + if (match(Op1, m_SExt(m_Value(A))) && A->getType()->isIntegerTy(1)) + return SelectInst::Create(A, ConstantInt::getSigned(I.getType(), -1), Op0); + // Note: If we've gotten to the point of visiting the outer OR, then the // inner one couldn't be simplified. If it was a constant, then it won't // be simplified by a later pass either, so we try swapping the inner/outer |