summaryrefslogtreecommitdiff
path: root/lib/Transforms/InstCombine/InstCombineCompares.cpp
diff options
context:
space:
mode:
authorPete Cooper <peter_cooper@apple.com>2011-12-01 19:13:26 +0000
committerPete Cooper <peter_cooper@apple.com>2011-12-01 19:13:26 +0000
commit165695d26161912f528e0a8dca0f22e9b6cfa57b (patch)
tree2eab78cf753669c1491315fbdc8e1ebd2a186614 /lib/Transforms/InstCombine/InstCombineCompares.cpp
parentcc1d856d8e8e11407b3c6c1d08768f77c3722e38 (diff)
downloadllvm-165695d26161912f528e0a8dca0f22e9b6cfa57b.tar.gz
llvm-165695d26161912f528e0a8dca0f22e9b6cfa57b.tar.bz2
llvm-165695d26161912f528e0a8dca0f22e9b6cfa57b.tar.xz
Improved fix for abs(val) != 0 to check other similar case. Also fixed style issues and confusing comment
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@145618 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r--lib/Transforms/InstCombine/InstCombineCompares.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp
index cebe37b7b0..249de571e5 100644
--- a/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -1796,15 +1796,19 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
return ReplaceInstUsesWith(I, V);
// comparing -val or val with non-zero is the same as just comparing val
- // ie, (val != 0) == (-val != 0)
+ // ie, abs(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)),
+ Value *Cond, *SelectTrue, *SelectFalse;
+ if (match(Op0, m_Select(m_Value(Cond), m_Value(SelectTrue),
m_Value(SelectFalse)))) {
- if (SubSrc == SelectFalse) {
- return CmpInst::Create(Instruction::ICmp, I.getPredicate(),
- SubSrc, Op1);
+ if (Value *V = dyn_castNegVal(SelectTrue)) {
+ if (V == SelectFalse)
+ return CmpInst::Create(Instruction::ICmp, I.getPredicate(), V, Op1);
+ }
+ else if (Value *V = dyn_castNegVal(SelectFalse)) {
+ if (V == SelectTrue)
+ return CmpInst::Create(Instruction::ICmp, I.getPredicate(), V, Op1);
}
}
}