[PATCH] D71583: [llvm][MIRVRegNamerUtils] Add support for hashing MachineOperand FrameIndices.

Puyan Lotfi via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 17:12:32 PST 2019


plotfi created this revision.
plotfi added reviewers: aditya_nandakumar, bogner.
Herald added subscribers: llvm-commits, arphaman, hiraditya.
Herald added a project: LLVM.

This patch makes it so that cases where multiple instructions that differ only in their frame-index MachineOperand values no longer collide. For instance:

  
  %1:_(p0) = G_FRAME_INDEX %stack.0
  %2:_(p0) = G_FRAME_INDEX %stack.1
  %3:gr32 = MOV32rm %fixed-stack.0, 1, _, 0, _
  %4:gr32 = MOV32rm %fixed-stack.1, 1, _, 0,


Prior to this patch the first two instructions would collide together.  Also, the last two instructions would also collide. Now they will no longer collide.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71583

Files:
  llvm/lib/CodeGen/MIRVRegNamerUtils.cpp
  llvm/test/CodeGen/MIR/X86/mir-namer-hash-frameindex.mir


Index: llvm/test/CodeGen/MIR/X86/mir-namer-hash-frameindex.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/MIR/X86/mir-namer-hash-frameindex.mir
@@ -0,0 +1,23 @@
+# RUN: llc -mtriple x86_64-linux-gnu -run-pass mir-canonicalizer -verify-machineinstrs %s -o - | FileCheck %s
+
+...
+---
+name: f
+stack:
+  - { id: 0, size: 4 }
+  - { id: 1, size: 4 }
+fixedStack:
+  - { id: 0, offset: 0, size: 4 }
+  - { id: 1, offset: 0, size: 4 }
+body: |
+  bb.1:
+    ; CHECK: _1:_(p0) = G_FRAME_INDEX %stack.{{[0-1]}}
+    ; CHECK: _1:_(p0) = G_FRAME_INDEX %stack.{{[0-1]}}
+    ; CHECK: _1:gr32 = MOV32rm %fixed-stack.{{[0-1]}}
+    ; CHECK: _1:gr32 = MOV32rm %fixed-stack.{{[0-1]}}
+    %1:_(p0) = G_FRAME_INDEX %stack.0
+    %2:_(p0) = G_FRAME_INDEX %stack.1
+    %3:gr32 = MOV32rm %fixed-stack.0, 1, _, 0, _
+    %4:gr32 = MOV32rm %fixed-stack.1, 1, _, 0, _
+
+...
Index: llvm/lib/CodeGen/MIRVRegNamerUtils.cpp
===================================================================
--- llvm/lib/CodeGen/MIRVRegNamerUtils.cpp
+++ llvm/lib/CodeGen/MIRVRegNamerUtils.cpp
@@ -68,6 +68,8 @@
       return MO.getImm();
     case MachineOperand::MO_TargetIndex:
       return MO.getOffset() | (MO.getTargetFlags() << 16);
+    case MachineOperand::MO_FrameIndex:
+      return llvm::hash_value(MO);
 
     // We could explicitly handle all the types of the MachineOperand,
     // here but we can just return a common number until we find a
@@ -77,7 +79,6 @@
 
     // TODO: Handle the following Index/ID/Predicate cases. They can
     // be hashed on in a stable manner.
-    case MachineOperand::MO_FrameIndex:
     case MachineOperand::MO_ConstantPoolIndex:
     case MachineOperand::MO_JumpTableIndex:
     case MachineOperand::MO_CFIIndex:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71583.234196.patch
Type: text/x-patch
Size: 1788 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191217/1f003f4b/attachment.bin>


More information about the llvm-commits mailing list