aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2018-05-21 18:42:42 +0000
committerCraig Topper <craig.topper@intel.com>2018-05-21 18:42:42 +0000
commitf14e62c9a53b20ed6ed3486588c5ac730cf50442 (patch)
tree22bcbfbaeb4ab42056a87a72ab9bdd957b2fbeca /llvm/lib/Analysis/ValueTracking.cpp
parent59a6fc469f5db71563fba093513ab7fde5e09f64 (diff)
downloadllvm-f14e62c9a53b20ed6ed3486588c5ac730cf50442.zip
llvm-f14e62c9a53b20ed6ed3486588c5ac730cf50442.tar.gz
llvm-f14e62c9a53b20ed6ed3486588c5ac730cf50442.tar.bz2
[EarlyCSE] Improve EarlyCSE of some absolute value cases.
Change matchSelectPattern to return X and -X for ABS/NABS in a well defined order. Adjust EarlyCSE to account for this. Ensure the SPF result is some kind of min/max and not abs/nabs in one place in InstCombine that made me nervous. Prevously we returned the two operands of the compare part of the abs pattern. The RHS is always going to be a 0i, 1 or -1 constant. This isn't a very meaningful thing to return for any one. There's also some freedom in the abs pattern as to what happens when the value is equal to 0. This freedom led to early cse failing to match when different constants were used in otherwise equivalent operations. By returning the input and its negation in a defined order we can ensure an exact match. This also makes sure both patterns use the exact same subtract instruction for the negation. I believe CSE should evebntually make this happen and properly merge the nsw/nuw flags. But I'm not familiar with CSE and what order it does things in so it seemed like it might be good to really enforce that they were the same. Differential Revision: https://reviews.llvm.org/D47037 llvm-svn: 332865
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 811c501..4442df8 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4574,6 +4574,8 @@ static SelectPatternResult matchSelectPattern(CmpInst::Predicate Pred,
if (match(CmpRHS, m_APInt(C1))) {
if ((CmpLHS == TrueVal && match(FalseVal, m_Neg(m_Specific(CmpLHS)))) ||
(CmpLHS == FalseVal && match(TrueVal, m_Neg(m_Specific(CmpLHS))))) {
+ // Set RHS to the negate operand. LHS was assigned to CmpLHS earlier.
+ RHS = (CmpLHS == TrueVal) ? FalseVal : TrueVal;
// ABS(X) ==> (X >s 0) ? X : -X and (X >s -1) ? X : -X
// NABS(X) ==> (X >s 0) ? -X : X and (X >s -1) ? -X : X