summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorJoseph Tremoulet <jotrem@microsoft.com>2019-06-17 19:11:28 +0000
committerJoseph Tremoulet <jotrem@microsoft.com>2019-06-17 19:11:28 +0000
commitdaa1ae6142956039137253b15a2da4e3ac44b89f (patch)
tree9ff9a9cf500b2f8d30c4fb88d4d65f01a3f1d371 /llvm/lib
parent7a0098aa6e36a60fd4a825c3a1ea1bddad141501 (diff)
downloadbcm5719-llvm-daa1ae6142956039137253b15a2da4e3ac44b89f.tar.gz
bcm5719-llvm-daa1ae6142956039137253b15a2da4e3ac44b89f.zip
[EarlyCSE] Fix hashing of self-compares
Summary: Update compare normalization in SimpleValue hashing to break ties (when the same value is being compared to itself) by switching to the swapped predicate if it has a lower numerical value. This brings the hashing in line with isEqual, which already recognizes the self-compares with swapped predicates as equal. Fixes PR 42280. Reviewers: spatel, efriedma, nikic, fhahn, uabelho Reviewed By: nikic Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63349 llvm-svn: 363598
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Scalar/EarlyCSE.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
index f9c6f88b9ec..f1f07525702 100644
--- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
+++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -174,12 +174,17 @@ static unsigned getHashValueImpl(SimpleValue Val) {
}
if (CmpInst *CI = dyn_cast<CmpInst>(Inst)) {
+ // Compares can be commuted by swapping the comparands and
+ // updating the predicate. Choose the form that has the
+ // comparands in sorted order, or in the case of a tie, the
+ // one with the lower predicate.
Value *LHS = CI->getOperand(0);
Value *RHS = CI->getOperand(1);
CmpInst::Predicate Pred = CI->getPredicate();
- if (Inst->getOperand(0) > Inst->getOperand(1)) {
+ CmpInst::Predicate SwappedPred = CI->getSwappedPredicate();
+ if (std::tie(LHS, Pred) > std::tie(RHS, SwappedPred)) {
std::swap(LHS, RHS);
- Pred = CI->getSwappedPredicate();
+ Pred = SwappedPred;
}
return hash_combine(Inst->getOpcode(), Pred, LHS, RHS);
}
OpenPOWER on IntegriCloud