[llvm] r301699 - Properly handle PHIs with subregisters in UnreachableBlockElim
Krzysztof Parzyszek via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 28 14:56:33 PDT 2017
Author: kparzysz
Date: Fri Apr 28 16:56:33 2017
New Revision: 301699
URL: http://llvm.org/viewvc/llvm-project?rev=301699&view=rev
Log:
Properly handle PHIs with subregisters in UnreachableBlockElim
When a PHI operand has a subregister, create a COPY instead of simply
replacing the PHI output with the input it.
Differential Revision: https://reviews.llvm.org/D32650
Added:
llvm/trunk/test/CodeGen/Hexagon/unreachable-mbb-phi-subreg.mir
Modified:
llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp
Modified: llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp?rev=301699&r1=301698&r2=301699&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp (original)
+++ llvm/trunk/lib/CodeGen/UnreachableBlockElim.cpp Fri Apr 28 16:56:33 2017
@@ -25,6 +25,7 @@
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/CodeGen/MachineDominators.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineLoopInfo.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
@@ -195,18 +196,30 @@ bool UnreachableMachineBlockElim::runOnM
}
if (phi->getNumOperands() == 3) {
- unsigned Input = phi->getOperand(1).getReg();
- unsigned Output = phi->getOperand(0).getReg();
-
- phi++->eraseFromParent();
+ const MachineOperand &Input = phi->getOperand(1);
+ const MachineOperand &Output = phi->getOperand(0);
+ unsigned InputReg = Input.getReg();
+ unsigned OutputReg = Output.getReg();
+ assert(Output.getSubReg() == 0 && "Cannot have output subregister");
ModifiedPHI = true;
- if (Input != Output) {
+ if (InputReg != OutputReg) {
MachineRegisterInfo &MRI = F.getRegInfo();
- MRI.constrainRegClass(Input, MRI.getRegClass(Output));
- MRI.replaceRegWith(Output, Input);
+ unsigned InputSub = Input.getSubReg();
+ if (InputSub == 0) {
+ MRI.constrainRegClass(InputReg, MRI.getRegClass(OutputReg));
+ MRI.replaceRegWith(OutputReg, InputReg);
+ } else {
+ // The input register to the PHI has a subregister:
+ // insert a COPY instead of simply replacing the output
+ // with the input.
+ const TargetInstrInfo *TII = F.getSubtarget().getInstrInfo();
+ BuildMI(*BB, BB->getFirstNonPHI(), phi->getDebugLoc(),
+ TII->get(TargetOpcode::COPY), OutputReg)
+ .addReg(InputReg, getRegState(Input), InputSub);
+ }
+ phi++->eraseFromParent();
}
-
continue;
}
Added: llvm/trunk/test/CodeGen/Hexagon/unreachable-mbb-phi-subreg.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Hexagon/unreachable-mbb-phi-subreg.mir?rev=301699&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Hexagon/unreachable-mbb-phi-subreg.mir (added)
+++ llvm/trunk/test/CodeGen/Hexagon/unreachable-mbb-phi-subreg.mir Fri Apr 28 16:56:33 2017
@@ -0,0 +1,25 @@
+# RUN: llc -march=hexagon -run-pass unreachable-mbb-elimination %s -o - | FileCheck %s
+
+---
+name: fred
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: %d0
+ successors: %bb.2
+
+ %0 : doubleregs = COPY %d0
+ J2_jump %bb.2, implicit-def %pc
+
+ bb.1:
+ successors: %bb.2
+ A2_nop
+
+ bb.2:
+ ; Make sure that the subregister from the PHI operand is preserved.
+ ; CHECK: %[[REG:[0-9]+]] = COPY %0.isub_lo
+ ; CHECK: %r0 = COPY %[[REG]]
+ %1 : intregs = PHI %0.isub_lo, %bb.0, %0.isub_hi, %bb.1
+ %r0 = COPY %1
+...
+
More information about the llvm-commits
mailing list