Replace the ad-hoc hashing in GVN with the new hashing infrastructure.

This implicitly fixes a nasty bug in the GVN hashing (that thankfully
could only manifest as a performance bug): actually include the opcode
in the hash. The old code started the hash off with the opcode, but then
overwrote it with the type pointer.

Since this is likely to be pretty hot (GVN being already pretty
expensive) I've included a micro-optimization to just not bother with
the varargs hashing if they aren't present. I can't measure any change
in GVN performance due to this, even with a big test case like Duncan's
sqlite one. Everything I see is in the noise floor. That said, this
closes a loop hole for a potential scaling problem due to collisions if
the opcode were the differentiating aspect of the expression.

llvm-svn: 152025
This commit is contained in:
Chandler Carruth 2012-03-05 11:29:54 +00:00
parent 189fa748ec
commit e134d1a336
1 changed files with 13 additions and 10 deletions

View File

@ -36,6 +36,7 @@
#include "llvm/Transforms/Utils/SSAUpdater.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/Allocator.h"
@ -84,6 +85,16 @@ namespace {
return false;
return true;
}
friend hash_code hash_value(const Expression &Value) {
// Optimize for the common case.
if (Value.varargs.empty())
return hash_combine(Value.opcode, Value.type);
return hash_combine(Value.opcode, Value.type,
hash_combine_range(Value.varargs.begin(),
Value.varargs.end()));
}
};
class ValueTable {
@ -130,16 +141,8 @@ template <> struct DenseMapInfo<Expression> {
}
static unsigned getHashValue(const Expression e) {
unsigned hash = e.opcode;
hash = ((unsigned)((uintptr_t)e.type >> 4) ^
(unsigned)((uintptr_t)e.type >> 9));
for (SmallVector<uint32_t, 4>::const_iterator I = e.varargs.begin(),
E = e.varargs.end(); I != E; ++I)
hash = *I + hash * 37;
return hash;
using llvm::hash_value;
return static_cast<unsigned>(hash_value(e));
}
static bool isEqual(const Expression &LHS, const Expression &RHS) {
return LHS == RHS;