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

Matthias Springer llvmlistbot at llvm.org
Wed Dec 13 20:15:30 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
----------------
matthias-springer wrote:

Can we hash every operand, then sort all hash codes (`hash_code` can be converted to `size_t`), then `hash_combine` them in that order?

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


More information about the Mlir-commits mailing list