diff options
author | Pete Cooper <peter_cooper@apple.com> | 2011-12-01 03:58:40 +0000 |
---|---|---|
committer | Pete Cooper <peter_cooper@apple.com> | 2011-12-01 03:58:40 +0000 |
commit | 65a6b57c330361d1075af146300d6aab9059659c (patch) | |
tree | 1bfe69eb5b5b86e661d97e27a56295cb0f20034f /lib/Transforms/InstCombine/InstCombineCompares.cpp | |
parent | 618c1dbd293d15ee19f61b1156ab8086ad28311a (diff) | |
download | llvm-65a6b57c330361d1075af146300d6aab9059659c.tar.gz llvm-65a6b57c330361d1075af146300d6aab9059659c.tar.bz2 llvm-65a6b57c330361d1075af146300d6aab9059659c.tar.xz |
Added instcombine pattern to spot comparing -val or val against 0.
(val != 0) == (-val != 0) so "abs(val) != 0" becomes "val != 0"
Fixes <rdar://problem/10482509>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145563 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r-- | lib/Transforms/InstCombine/InstCombineCompares.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp index 274758ccb4..cebe37b7b0 100644 --- a/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1795,6 +1795,20 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) { if (Value *V = SimplifyICmpInst(I.getPredicate(), Op0, Op1, TD)) return ReplaceInstUsesWith(I, V); + // comparing -val or val with non-zero is the same as just comparing val + // ie, (val != 0) == (-val != 0) + if (I.getPredicate() == ICmpInst::ICMP_NE && match(Op1, m_Zero())) + { + Value *Cond, *SubSrc, *SelectFalse; + if (match(Op0, m_Select(m_Value(Cond), m_Sub(m_Zero(), m_Value(SubSrc)), + m_Value(SelectFalse)))) { + if (SubSrc == SelectFalse) { + return CmpInst::Create(Instruction::ICmp, I.getPredicate(), + SubSrc, Op1); + } + } + } + Type *Ty = Op0->getType(); // icmp's with boolean values can always be turned into bitwise operations |