[PATCH] D63349: [EarlyCSE] Fix hashing of self-compares

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 17 12:10:04 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL363598: [EarlyCSE] Fix hashing of self-compares (authored by josepht, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D63349?vs=204820&id=205146#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63349/new/

https://reviews.llvm.org/D63349

Files:
  llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
  llvm/trunk/test/Transforms/EarlyCSE/commute.ll


Index: llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
===================================================================
--- llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
+++ llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
@@ -174,12 +174,17 @@
   }
 
   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);
   }
Index: llvm/trunk/test/Transforms/EarlyCSE/commute.ll
===================================================================
--- llvm/trunk/test/Transforms/EarlyCSE/commute.ll
+++ llvm/trunk/test/Transforms/EarlyCSE/commute.ll
@@ -72,6 +72,22 @@
   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) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63349.205146.patch
Type: text/x-patch
Size: 1834 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190617/6fdd1a58/attachment.bin>


More information about the llvm-commits mailing list