<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-CA" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">There’s also llvm/Support/xxhash.h if the other one falls short.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="FR">De :</span></b><span lang="FR"> llvm-dev <llvm-dev-bounces@lists.llvm.org>
<b>De la part de</b> David Blaikie via llvm-dev<br>
<b>Envoyé :</b> September 10, 2021 3:28 AM<br>
<b>À :</b> Jeroen Dobbelaere <Jeroen.Dobbelaere@synopsys.com><br>
<b>Cc :</b> llvm-dev@lists.llvm.org<br>
<b>Objet :</b> Re: [llvm-dev] DenseMapInfo::getHashValue() of two sometimes identical pointers<o:p></o:p></span></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">straight up ^ isn't a very good hash algorithm, as you're seeing - my understanding was even a rudimentary hash algorithm multiplied the previous value by a prime before combining it<br>
<br>
But I think we have a library in llvm for hashing that probably does something pretty good, whatever it is - llvm/ADT/Hashing.h - probably use that? (hash_combine(x, y, z), I guess?)<o:p></o:p></p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Thu, Sep 9, 2021 at 11:54 PM Jeroen Dobbelaere via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal">Hi all,<br>
<br>
is there a recommended way to implement a 'DenseMapInfo<..>::getHashValue()'<br>
for a class that contains multiple pointers of which some are potentially identical ?<br>
<br>
The standard used xor (^) is canceling out the hash contribution of those identical pointers.<br>
<br>
More concrete: I am adding a 'PtrProvenance' member to MemoryLocation. When I add<br>
the member to the hash computation in the way it seems intended,<br>
<br>
<a href="https://can01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fllvm%2Fllvm-project%2Fblob%2Fmain%2Fllvm%2Finclude%2Fllvm%2FAnalysis%2FMemoryLocation.h%23L340-L344&data=04%7C01%7Calexandre.ganea%40ubisoft.com%7Cdf96dd5e086d45c8e7d708d9742c8365%7Ce01bd386fa514210a2a429e5ab6f7ab1%7C0%7C0%7C637668556806959902%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=mPYakZcvSfRQy9ikkdJXev04gORdd1obhlpJGnG4d9E%3D&reserved=0" target="_blank">https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Analysis/MemoryLocation.h#L340-L344</a><br>
<br>
I would do:<br>
<br>
  static unsigned getHashValue(const MemoryLocation &Val) {<br>
      return DenseMapInfo<const Value *>::getHashValue(Val.Ptr) ^<br>
           DenseMapInfo<const Value *>::getHashValue(Val.PtrProvenance) ^ // Handle new member<br>
           DenseMapInfo<LocationSize>::getHashValue(Val.Size) ^<br>
           DenseMapInfo<AAMDNodes>::getHashValue(Val.AATags);<br>
  }<br>
<br>
<br>
But, in the initial case, it is very likely that Val.Ptr == Val.PtrProvenance.<br>
<br>
Is there a recommended (standard) way to fix this ?<br>
<br>
Thanks,<br>
<br>
Jeroen Dobbelaere<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://can01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.llvm.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fllvm-dev&data=04%7C01%7Calexandre.ganea%40ubisoft.com%7Cdf96dd5e086d45c8e7d708d9742c8365%7Ce01bd386fa514210a2a429e5ab6f7ab1%7C0%7C0%7C637668556806959902%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=yT0s9nCIFCLOjrMxwElDfXQ0FUMb0RUDEDXMLkz8GLw%3D&reserved=0" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</body>
</html>