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 | 3ec01b7dac769449723a25d8f7d33b49c917ccc9 (patch) | |
tree | a4a10203cb5dbc49036e542f5e40b9d73c56d46d /lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | |
parent | f6832bbda08b6975caa264de183bf3ee1d472aca (diff) | |
download | llvm-3ec01b7dac769449723a25d8f7d33b49c917ccc9.tar.gz llvm-3ec01b7dac769449723a25d8f7d33b49c917ccc9.tar.bz2 llvm-3ec01b7dac769449723a25d8f7d33b49c917ccc9.tar.xz |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129545 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineAndOrXor.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 1cb18e12ee..6cf405328a 100644 --- a/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/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 |