[llvm] Deduplication of cyclic PHI nodes (PR #86662)

via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 8 07:11:27 PDT 2024


================
@@ -1406,15 +1446,16 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
       return PN == getEmptyKey() || PN == getTombstoneKey();
     }
 
-    // WARNING: this logic must be kept in sync with
-    //          Instruction::isIdenticalToWhenDefined()!
     static unsigned getHashValueImpl(PHINode *PN) {
-      // Compute a hash value on the operands. Instcombine will likely have
-      // sorted them, which helps expose duplicates, but we have to check all
-      // the operands to be safe in case instcombine hasn't run.
-      return static_cast<unsigned>(hash_combine(
-          hash_combine_range(PN->value_op_begin(), PN->value_op_end()),
-          hash_combine_range(PN->block_begin(), PN->block_end())));
+      unsigned Result = 0;
+      for (int i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
+        auto *Incoming = PN->getIncomingValue(i);
+        if (!isa<PHINode>(Incoming))
+          Result +=
----------------
annamthomas wrote:

Pls add a comment on why you're using a custom hash of the value and block, rather than the hash_combine_range function used by all hash implementations for instructions. 

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


More information about the llvm-commits mailing list