Skip to content

Commit f04d67f

Browse files
fixup! try improving getHashValue
1 parent 4190352 commit f04d67f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

llvm/lib/Transforms/Utils/SimplifyCFG.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7463,8 +7463,25 @@ template <> struct DenseMapInfo<const CaseHandleWrapper *> {
74637463
static unsigned getHashValue(const CaseHandleWrapper *CT) {
74647464
BasicBlock *Succ = CT->Case.getCaseSuccessor();
74657465
BranchInst *BI = cast<BranchInst>(Succ->getTerminator());
7466-
auto It = BI->successors();
7467-
return hash_combine(Succ->size(), hash_combine_range(It.begin(), It.end()));
7466+
assert(BI->isUnconditional() &&
7467+
"Only supporting unconditional branches for now");
7468+
assert(BI->getNumSuccessors() == 1 &&
7469+
"Expected unconditional branches to have one successor");
7470+
assert(Succ->size() == 1 && "Expected just a single branch in the BB");
7471+
7472+
// Since we assume the BB is just a single BranchInst with a single
7473+
// succsessor, we hash as the BB and the incoming Values of its PHIs.
7474+
// Initially, we tried to just use the sucessor BB as the hash, but this had
7475+
// poor performance. We find that the extra computation of getting the
7476+
// incoming PHI values here leads to better performance on overall Set
7477+
// performance.
7478+
BasicBlock *BB = BI->getSuccessor(0);
7479+
SmallVector<Value *> PhiValsForBB;
7480+
for (PHINode &Phi : BB->phis())
7481+
PhiValsForBB.emplace_back(CT->PhiPredIVs[&Phi][BB]);
7482+
7483+
return hash_combine(
7484+
BB, hash_combine_range(PhiValsForBB.begin(), PhiValsForBB.end()));
74687485
}
74697486
static bool isEqual(const CaseHandleWrapper *LHS,
74707487
const CaseHandleWrapper *RHS) {

0 commit comments

Comments
 (0)