[PATCH] D16404: [X86] Use hash table in LEA optimization pass

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 21 10:59:15 PST 2016


dberlin added inline comments.

================
Comment at: lib/Target/X86/X86OptimizeLEAs.cpp:100
@@ +99,3 @@
+    size_t Hash = hash_value(*Key.Operands[0]);
+    Hash |= hash_value(*Key.Operands[1]) << 32;
+    Hash |= hash_value(*Key.Operands[2]) >> 32;
----------------
qcolombet wrote:
> This may be undefined behavior if size_t is a 32-bit value.
> In other words, promote the computation on int64_t, then convert to the size_t type.
Or just use hash_code as the type :)


================
Comment at: lib/Target/X86/X86OptimizeLEAs.cpp:103
@@ +102,3 @@
+    Hash |= hash_value(*Key.Operands[3]);
+
+    // If the address displacement is an immediate, it should not affect the
----------------
You should just use hash_combine, which will call hash_value.

IE

  hash_code Hash = hash_combine(*Key.Operands[0], *Key.Operands[1], *Key.Operands[2], *Key.Operands[3]);
  if (Key.Disp->isGlobal())
    Hash = hash_combine(Hash, Key.Disp->getGlobal());


This will do all the mixing and calling of hash_value for you, and you won't need anything else in this function.


  


http://reviews.llvm.org/D16404





More information about the llvm-commits mailing list