[PATCH] D44918: [RegisterCoalescing] Don't move COPY if it would interfere with another value
Mikael Holmén via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 27 23:04:34 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL328689: [RegisterCoalescing] Don't move COPY if it would interfere with another value (authored by uabelho, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D44918?vs=139890&id=140044#toc
Repository:
rL LLVM
https://reviews.llvm.org/D44918
Files:
llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp
llvm/trunk/test/CodeGen/Mips/coalesce-partial-redundant-reguse-terminator.mir
Index: llvm/trunk/test/CodeGen/Mips/coalesce-partial-redundant-reguse-terminator.mir
===================================================================
--- llvm/trunk/test/CodeGen/Mips/coalesce-partial-redundant-reguse-terminator.mir
+++ llvm/trunk/test/CodeGen/Mips/coalesce-partial-redundant-reguse-terminator.mir
@@ -0,0 +1,41 @@
+# RUN: llc -march=mips64 -o - %s -run-pass=simple-register-coalescing | FileCheck %s
+
+---
+name: f
+tracksRegLiveness: true
+body: |
+ bb.0:
+ successors: %bb.1
+
+ %21:gpr32 = ADDiu $zero, 0
+ %22:gpr32 = COPY %21
+ %22:gpr32 = ADDiu %22, 1
+ J %bb.1, implicit-def dead $at
+
+ bb.1:
+ successors: %bb.2
+
+ BEQ %22, $zero, %bb.2, implicit-def $at
+
+ bb.2:
+ successors: %bb.2, %bb.3
+
+ %22:gpr32 = COPY %21
+ %21:gpr32 = COPY %22
+ BEQ undef %0:gpr32, $zero, %bb.2, implicit-def $at
+
+ bb.3:
+
+...
+
+# We should not hoist the
+#
+# %22:gpr32 = COPY %21
+#
+# into bb.1 since %22 is used in the BEQ.
+
+# CHECK-LABEL: bb.1:
+# CHECK-NOT: COPY
+# CHECK: BEQ
+
+# CHECK-LABEL: bb.2:
Index: llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp
===================================================================
--- llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp
+++ llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp
@@ -989,13 +989,24 @@
if (CopyLeftBB && CopyLeftBB->succ_size() > 1)
return false;
- // Now ok to move copy.
+ // Now (almost sure it's) ok to move copy.
if (CopyLeftBB) {
+ // Position in CopyLeftBB where we should insert new copy.
+ auto InsPos = CopyLeftBB->getFirstTerminator();
+
+ // Make sure that B isn't referenced in the terminators (if any) at the end
+ // of the predecessor since we're about to insert a new definition of B
+ // before them.
+ if (InsPos != CopyLeftBB->end()) {
+ SlotIndex InsPosIdx = LIS->getInstructionIndex(*InsPos).getRegSlot(true);
+ if (IntB.overlaps(InsPosIdx, LIS->getMBBEndIdx(CopyLeftBB)))
+ return false;
+ }
+
DEBUG(dbgs() << "\tremovePartialRedundancy: Move the copy to "
<< printMBBReference(*CopyLeftBB) << '\t' << CopyMI);
// Insert new copy to CopyLeftBB.
- auto InsPos = CopyLeftBB->getFirstTerminator();
MachineInstr *NewCopyMI = BuildMI(*CopyLeftBB, InsPos, CopyMI.getDebugLoc(),
TII->get(TargetOpcode::COPY), IntB.reg)
.addReg(IntA.reg);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44918.140044.patch
Type: text/x-patch
Size: 2468 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180328/c12d5deb/attachment.bin>
More information about the llvm-commits
mailing list