[flang-commits] [mlir] [flang] [mlir] Handle simple commutative cases in CSE. (PR #75274)

Jacques Pienaar via flang-commits flang-commits at lists.llvm.org
Thu Dec 14 09:34:26 PST 2023


================
@@ -683,8 +683,17 @@ llvm::hash_code OperationEquivalence::computeHash(
     hash = llvm::hash_combine(hash, op->getLoc());
 
   //   - Operands
-  for (Value operand : op->getOperands())
-    hash = llvm::hash_combine(hash, hashOperands(operand));
+  if (op->hasTrait<mlir::OpTrait::IsCommutative>() &&
+      op->getNumOperands() > 0) {
+    // If commutative, don't hash the operands as hash is not order independent
+    // and even if it were would not be sufficient for CSE usage.
+    // FIXME: This has the effect of resulting in more hash collisions
----------------
jpienaar wrote:

AFAICS CSE ends up bucketing based on the hash of values and only those in same bucket are considered for comparison. Now that doesn't affect the current change as I'm just looking at reordering of values without considering equivalence below (except for the "simple" case, but that is equivalent to existing state).

https://github.com/llvm/llvm-project/pull/75274


More information about the flang-commits mailing list