diff options
author | Joseph Tremoulet <jotrem@microsoft.com> | 2019-06-17 19:11:28 +0000 |
---|---|---|
committer | Joseph Tremoulet <jotrem@microsoft.com> | 2019-06-17 19:11:28 +0000 |
commit | daa1ae6142956039137253b15a2da4e3ac44b89f (patch) | |
tree | 9ff9a9cf500b2f8d30c4fb88d4d65f01a3f1d371 | |
parent | 7a0098aa6e36a60fd4a825c3a1ea1bddad141501 (diff) | |
download | bcm5719-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
-rw-r--r-- | llvm/lib/Transforms/Scalar/EarlyCSE.cpp | 9 | ||||
-rw-r--r-- | llvm/test/Transforms/EarlyCSE/commute.ll | 16 |
2 files changed, 23 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); } diff --git a/llvm/test/Transforms/EarlyCSE/commute.ll b/llvm/test/Transforms/EarlyCSE/commute.ll index 572336c4ec4..0c8639b5e73 100644 --- a/llvm/test/Transforms/EarlyCSE/commute.ll +++ b/llvm/test/Transforms/EarlyCSE/commute.ll @@ -72,6 +72,22 @@ define void @test5(i32 %A, i32 %B, i1* %PA, i1* %PB) { ret void } +; Test degenerate case of commuted compare of identical comparands. + +define void @test6(float %f, i1* %p1, i1* %p2) { +; CHECK-LABEL: @test6( +; CHECK-NEXT: [[C1:%.*]] = fcmp ult float [[F:%.*]], [[F]] +; CHECK-NEXT: store i1 [[C1]], i1* [[P1:%.*]] +; CHECK-NEXT: store i1 [[C1]], i1* [[P2:%.*]] +; CHECK-NEXT: ret void +; + %c1 = fcmp ult float %f, %f + %c2 = fcmp ugt float %f, %f + store i1 %c1, i1* %p1 + store i1 %c2, i1* %p2 + ret void +} + ; Min/max operands may be commuted in the compare and select. define i8 @smin_commute(i8 %a, i8 %b) { |