summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorPete Cooper <peter_cooper@apple.com>2011-12-01 03:58:40 +0000
committerPete Cooper <peter_cooper@apple.com>2011-12-01 03:58:40 +0000
commitbc5c524b71d97f31a8954b6e81b65c077763b1b3 (patch)
treea3fd45ac3c0b4664d233144909d1c236f8630bfd /llvm/lib/Transforms
parentb1a02922405c72dce18686750f809f154b04f859 (diff)
downloadbcm5719-llvm-bc5c524b71d97f31a8954b6e81b65c077763b1b3.tar.gz
bcm5719-llvm-bc5c524b71d97f31a8954b6e81b65c077763b1b3.zip
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> llvm-svn: 145563
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 274758ccb4b..cebe37b7b0a 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/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
OpenPOWER on IntegriCloud