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

Jacques Pienaar via flang-commits flang-commits at lists.llvm.org
Wed Dec 13 20:56:49 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:

We could make it commutative here yes, but we actually need to hash based on the equivalence class additionally here to ensure they end with same hash before we compare. But we don't know those when we just hash.

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


More information about the flang-commits mailing list