[llvm] [SimplifyCFG] Use hash map to continue hoisting the common instructions (PR #78615)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 9 04:10:56 PST 2024
================
@@ -1582,19 +1582,29 @@ hoistLockstepIdenticalDPValues(Instruction *TI, Instruction *I1,
}
}
+// Hash instructions based on following factors:
+// 1- Instruction Opcode
+// 2- Instruction type
+// 3- Instruction operands
+llvm::hash_code getHash(Instruction *Instr) {
+ std::vector<Value *> operands(Instr->op_begin(), Instr->op_end());
+ return llvm::hash_combine(
+ Instr->getOpcode(), Instr->getType(),
+ hash_combine_range(operands.begin(), operands.end()));
----------------
dtcxzyw wrote:
```suggestion
return llvm::hash_combine(
Instr->getOpcode(), Instr->getType(),
hash_combine_range(Instr->op_begin(), Instr->op_end()));
```
TBH I think it is dangerous to calculate hashes for pointers :(
It will make the optimization result non-deterministic if it depends on the iteration order of the hashmap.
https://github.com/llvm/llvm-project/pull/78615
More information about the llvm-commits
mailing list