Skip to content

Commit 65eb2f3

Browse files
committedOct 4, 2017
[UnreachableBlockElim] Use COPY if PHI input is undef
Summary: If we have %vreg0<def> = PHI %vreg2<undef>, <BB#0>, %vreg3, <BB#2>; GR32:%vreg0,%vreg2,%vreg3 %vreg3<def,tied1> = ADD32ri8 %vreg0<kill,tied0>, 1, %EFLAGS<imp-def>; GR32:%vreg3,%vreg0 then we can't just change %vreg0 into %vreg3, since %vreg2 is actually undef. We would have to also copy the undef flag to be able to change the register. Instead we deal with this case like other cases where we can't just replace the register: we insert a COPY. The code creating the COPY already copied all flags from the PHI input, so the undef flag will be transferred as it should. Reviewers: kparzysz Reviewed By: kparzysz Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D38235 llvm-svn: 314879
1 parent f279d9b commit 65eb2f3

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed
 

‎llvm/lib/CodeGen/UnreachableBlockElim.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,12 @@ bool UnreachableMachineBlockElim::runOnMachineFunction(MachineFunction &F) {
207207
MachineRegisterInfo &MRI = F.getRegInfo();
208208
unsigned InputSub = Input.getSubReg();
209209
if (InputSub == 0 &&
210-
MRI.constrainRegClass(InputReg, MRI.getRegClass(OutputReg))) {
210+
MRI.constrainRegClass(InputReg, MRI.getRegClass(OutputReg)) &&
211+
!Input.isUndef()) {
211212
MRI.replaceRegWith(OutputReg, InputReg);
212213
} else {
213214
// The input register to the PHI has a subregister or it can't be
214-
// constrained to the proper register class:
215+
// constrained to the proper register class or it is undef:
215216
// insert a COPY instead of simply replacing the output
216217
// with the input.
217218
const TargetInstrInfo *TII = F.getSubtarget().getInstrInfo();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# RUN: llc %s -o - -run-pass=processimpdefs -run-pass=unreachable-mbb-elimination | FileCheck %s
2+
---
3+
name: f
4+
tracksRegLiveness: true
5+
registers:
6+
- { id: 0, class: gr32, preferred-register: '' }
7+
- { id: 1, class: gr32, preferred-register: '' }
8+
- { id: 2, class: gr32, preferred-register: '' }
9+
body: |
10+
bb.0:
11+
%0 = IMPLICIT_DEF
12+
JMP_1 %bb.1
13+
14+
bb.1:
15+
%1 = PHI %0, %bb.0, %2, %bb.2
16+
%2 = ADD32ri8 killed %1, 1, implicit-def %eflags
17+
JMP_1 %bb.3
18+
19+
bb.2:
20+
JMP_1 %bb.1
21+
22+
bb.3:
23+
...
24+
25+
# bb2 above is dead and should be removed and the PHI should be replaced with a
26+
# COPY from an undef value since the bb0 value in the PHI is undef.
27+
28+
# CHECK: bb.0:
29+
# CHECK: successors: %bb.1
30+
# CHECK: JMP_1 %bb.1
31+
32+
# CHECK: bb.1:
33+
# CHECK: successors: %bb.2
34+
# CHECK: [[TMP1:%[0-9]+]] = COPY undef %{{[0-9]+}}
35+
# CHECK: %{{[0-9]+}} = ADD32ri8 killed [[TMP1]], 1
36+
# CHECK: JMP_1 %bb.2
37+
38+
# CHECK: bb.2:

0 commit comments

Comments
 (0)
Please sign in to comment.