llvm.org GIT mirror llvm / 12c73fa
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363598 91177308-0d34-0410-b5e6-96231b3b80d8 Joseph Tremoulet 3 months ago
2 changed file(s) with 23 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
173173 }
174174
175175 if (CmpInst *CI = dyn_cast(Inst)) {
176 // Compares can be commuted by swapping the comparands and
177 // updating the predicate. Choose the form that has the
178 // comparands in sorted order, or in the case of a tie, the
179 // one with the lower predicate.
176180 Value *LHS = CI->getOperand(0);
177181 Value *RHS = CI->getOperand(1);
178182 CmpInst::Predicate Pred = CI->getPredicate();
179 if (Inst->getOperand(0) > Inst->getOperand(1)) {
183 CmpInst::Predicate SwappedPred = CI->getSwappedPredicate();
184 if (std::tie(LHS, Pred) > std::tie(RHS, SwappedPred)) {
180185 std::swap(LHS, RHS);
181 Pred = CI->getSwappedPredicate();
186 Pred = SwappedPred;
182187 }
183188 return hash_combine(Inst->getOpcode(), Pred, LHS, RHS);
184189 }
6868 store i1 %C, i1* %PA
6969 %D = icmp slt i32 %B, %A
7070 store i1 %D, i1* %PB
71 ret void
72 }
73
74 ; Test degenerate case of commuted compare of identical comparands.
75
76 define void @test6(float %f, i1* %p1, i1* %p2) {
77 ; CHECK-LABEL: @test6(
78 ; CHECK-NEXT: [[C1:%.*]] = fcmp ult float [[F:%.*]], [[F]]
79 ; CHECK-NEXT: store i1 [[C1]], i1* [[P1:%.*]]
80 ; CHECK-NEXT: store i1 [[C1]], i1* [[P2:%.*]]
81 ; CHECK-NEXT: ret void
82 ;
83 %c1 = fcmp ult float %f, %f
84 %c2 = fcmp ugt float %f, %f
85 store i1 %c1, i1* %p1
86 store i1 %c2, i1* %p2
7187 ret void
7288 }
7389