[llvm-commits] [llvm] r159741 - /llvm/trunk/lib/CodeGen/MachineInstr.cpp

Chandler Carruth chandlerc at gmail.com
Thu Jul 5 03:03:57 PDT 2012


Author: chandlerc
Date: Thu Jul  5 05:03:57 2012
New Revision: 159741

URL: http://llvm.org/viewvc/llvm-project?rev=159741&view=rev
Log:
The hash function for MI expressions, used by MachineCSE, is really
broken. This patch fixes the superficial problems which lead to the
intractably slow compile times reported in PR13225.

The specific issue is that we were failing to include the *offset* of
a global variable in the hash code. Oops. This would in turn cause all
MIs which were only distinguishable due to operating on different
offsets of a global variable to produce identical hash functions. In
some of the test cases attached to the PR I saw hash table activity
where there were O(1000) probes-per-lookup *on average*. A very few
entries were responsible for most of these probes.

There is still quite a bit more to do here. The ad-hoc layering of data
in MachineOperands makes them *extremely* brittle to hash correctly.
We're missing quite a few other cases, the only ones I've fixed here are
the specific MO types which were allowed through the assert() in
getOffset().

Modified:
    llvm/trunk/lib/CodeGen/MachineInstr.cpp

Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=159741&r1=159740&r2=159741&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Thu Jul  5 05:03:57 2012
@@ -1882,19 +1882,24 @@
       HashComponents.push_back(hash_combine(MO.getType(), MO.getImm()));
       break;
     case MachineOperand::MO_FrameIndex:
-    case MachineOperand::MO_ConstantPoolIndex:
     case MachineOperand::MO_JumpTableIndex:
       HashComponents.push_back(hash_combine(MO.getType(), MO.getIndex()));
       break;
+    case MachineOperand::MO_ConstantPoolIndex:
+      HashComponents.push_back(hash_combine(MO.getType(), MO.getIndex(),
+                                            MO.getOffset()));
+      break;
     case MachineOperand::MO_MachineBasicBlock:
       HashComponents.push_back(hash_combine(MO.getType(), MO.getMBB()));
       break;
     case MachineOperand::MO_GlobalAddress:
-      HashComponents.push_back(hash_combine(MO.getType(), MO.getGlobal()));
+      HashComponents.push_back(hash_combine(MO.getType(), MO.getGlobal(),
+                                            MO.getOffset()));
       break;
     case MachineOperand::MO_BlockAddress:
       HashComponents.push_back(hash_combine(MO.getType(),
-                                            MO.getBlockAddress()));
+                                            MO.getBlockAddress(),
+                                            MO.getOffset()));
       break;
     case MachineOperand::MO_MCSymbol:
       HashComponents.push_back(hash_combine(MO.getType(), MO.getMCSymbol()));





More information about the llvm-commits mailing list