aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
diff options
context:
space:
mode:
authorSanjoy Das <sanjoy@playingwithpointers.com>2015-04-30 04:56:00 +0000
committerSanjoy Das <sanjoy@playingwithpointers.com>2015-04-30 04:56:00 +0000
commita8c178f280806d6a0fadb8067e9e433a61e3296b (patch)
treeba0515ac8dfa5407f574d7b4cccee7632c455d25 /llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
parent9c821037434dc106543d6905f5519b1129eb904f (diff)
downloadllvm-a8c178f280806d6a0fadb8067e9e433a61e3296b.zip
llvm-a8c178f280806d6a0fadb8067e9e433a61e3296b.tar.gz
llvm-a8c178f280806d6a0fadb8067e9e433a61e3296b.tar.bz2
[InstCombine] Add a new formula for SMIN.
Summary: After this change `MatchSelectPattern` recognizes the following form of SMIN: Y >s C ? ~Y : ~C == ~Y <s ~C ? ~Y : ~C = SMIN(~Y, ~C) Reviewers: majnemer Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9352 llvm-svn: 236202
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index b28611f..6739314 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -86,6 +86,17 @@ MatchSelectPattern(Value *V, Value *&LHS, Value *&RHS) {
return (CmpLHS == FalseVal) ? SPF_ABS : SPF_NABS;
}
}
+
+ // Y >s C ? ~Y : ~C == ~Y <s ~C ? ~Y : ~C = SMIN(~Y, ~C)
+ if (const auto *C2 = dyn_cast<ConstantInt>(FalseVal)) {
+ if (C1->getType() == C2->getType() && ~C1->getValue() == C2->getValue() &&
+ (match(TrueVal, m_Not(m_Specific(CmpLHS))) ||
+ match(CmpLHS, m_Not(m_Specific(TrueVal))))) {
+ LHS = TrueVal;
+ RHS = FalseVal;
+ return SPF_SMIN;
+ }
+ }
}
// TODO: (X > 4) ? X : 5 --> (X >= 5) ? X : 5 --> MAX(X, 5)