summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Foad <jay.foad@gmail.com>2012-02-27 11:00:17 +0000
committerJay Foad <jay.foad@gmail.com>2012-02-27 11:00:17 +0000
commit8e9d47c039b56e457ed2578e75fec2e40eeae664 (patch)
treecbb417fb8e4c946fb91c4332bc7b83f20a8da085
parent1be25a78f71e3f7a36358b2ed7e387a65015c61c (diff)
downloadbcm5719-llvm-8e9d47c039b56e457ed2578e75fec2e40eeae664.tar.gz
bcm5719-llvm-8e9d47c039b56e457ed2578e75fec2e40eeae664.zip
Help the compiler to eliminate some dead code when hashing an array of T
where sizeof (T) is a multiple of 4. llvm-svn: 151523
-rw-r--r--llvm/include/llvm/ADT/Hashing.h8
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h
index 27c411e3223..682dc223e22 100644
--- a/llvm/include/llvm/ADT/Hashing.h
+++ b/llvm/include/llvm/ADT/Hashing.h
@@ -142,6 +142,7 @@ private:
}
// Add a range of bytes from I to E.
+ template<bool ElementsHaveEvenLength>
void addBytes(const char *I, const char *E) {
uint32_t Data;
// Note that aliasing rules forbid us from dereferencing
@@ -154,7 +155,7 @@ private:
std::memcpy(&Data, I, sizeof Data);
mix(Data);
}
- if (I != E) {
+ if (!ElementsHaveEvenLength && I != E) {
Data = 0;
std::memcpy(&Data, I, E - I);
mix(Data);
@@ -164,8 +165,9 @@ private:
// Add a range of bits from I to E.
template<typename T>
void addBits(const T *I, const T *E) {
- addBytes(reinterpret_cast<const char *>(I),
- reinterpret_cast<const char *>(E));
+ addBytes<sizeof (T) % sizeof (uint32_t) == 0>(
+ reinterpret_cast<const char *>(I),
+ reinterpret_cast<const char *>(E));
}
};
OpenPOWER on IntegriCloud