[llvm] [SimplifyCFG] Fix hoisting problem in SimplifyCFG (PR #78615)
Quentin Dian via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 1 22:29:45 PST 2024
================
@@ -1589,80 +1610,121 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(BasicBlock *BB,
}
bool Changed = false;
+ auto *SuccIterPairBegin = SuccIterPairs.begin();
+ SuccIterPairBegin++;
+ auto OtherSuccIterPairRange =
+ iterator_range(SuccIterPairBegin, SuccIterPairs.end());
+ auto OtherSuccIterRange = make_first_range(OtherSuccIterPairRange);
+ using InstrFlagPair = std::pair<Instruction *, unsigned>;
+ SmallVector<DenseMap<llvm::hash_code, InstrFlagPair>, 2> OtherSuccessorsHash;
+
+ for (auto BBItrPair : OtherSuccIterRange) {
+ // Fill the hashmap for every other successor
+ DenseMap<llvm::hash_code, InstrFlagPair> hashMap;
----------------
DianQK wrote:
> That's correct, in some cases (not often though) it might happen so I when I look up an instruction from hashmaps, I also check it to be identical to the instruction I'm hoisting with.
Hmm, sorry, I am referring to that when creating this map, we may lose the same hash value with different instructions. Maybe you could try something like this `Map<SomeHash, Vec<Instruction *>>`? You can also quickly skip some instructions directly by the size of the `Vec`. Perhaps you can find a similar approach at https://llvm.org/docs/ProgrammersManual.html.
https://github.com/llvm/llvm-project/pull/78615
More information about the llvm-commits
mailing list