Skip to content

Commit eb1a571

Browse files
authored
[SystemZ] Replace SELRMux with COPY in case of identical operands. (llvm#125108)
If both operands of a SELRMux use the same register which is killed, and the SELRMux is expanded to a jump sequence, a broken MIR results if the kill flag is not removed. This patch replaces the SELRMux with a COPY in these cases.
1 parent 9cf8ee9 commit eb1a571

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

llvm/lib/Target/SystemZ/SystemZPostRewrite.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ void SystemZPostRewrite::selectSELRMux(MachineBasicBlock &MBB,
107107
bool Src1IsHigh = SystemZ::isHighReg(Src1Reg);
108108
bool Src2IsHigh = SystemZ::isHighReg(Src2Reg);
109109

110+
// In rare cases both sources are the same register (after
111+
// machine-cse). This must be handled as it may lead to wrong-code (after
112+
// machine-cp) if the kill flag on Src1 isn't cleared (with
113+
// expandCondMove()).
114+
if (Src1Reg == Src2Reg) {
115+
BuildMI(*MBBI->getParent(), MBBI, MBBI->getDebugLoc(),
116+
TII->get(SystemZ::COPY), DestReg)
117+
.addReg(MBBI->getOperand(1).getReg(), getRegState(MBBI->getOperand(1)));
118+
MBBI->eraseFromParent();
119+
return;
120+
}
121+
110122
// If sources and destination aren't all high or all low, we may be able to
111123
// simplify the operation by moving one of the sources to the destination
112124
// first. But only if this doesn't clobber the other source.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# RUN: llc -o - %s -mtriple=s390x-linux-gnu -mcpu=z15 -run-pass=systemz-post-rewrite \
2+
# RUN: 2>&1 | FileCheck %s
3+
4+
# The SELRMux has two identical sources - replace with a copy instruction.
5+
# CHECK: name: fun0
6+
# CHECK: renamable $r1l = AHIMuxK killed renamable $r1l, -1, implicit-def dead $cc
7+
# CHECK-NEXT: CHIMux renamable $r5h, 9, implicit-def $cc
8+
# CHECK-NEXT: $r14h = COPY killed renamable $r1l
9+
---
10+
name: fun0
11+
tracksRegLiveness: true
12+
body: |
13+
bb.0:
14+
liveins: $r1l, $r5h
15+
renamable $r1l = AHIMuxK killed renamable $r1l, -1, implicit-def dead $cc
16+
CHIMux renamable $r5h, 9, implicit-def $cc
17+
renamable $r14h = SELRMux killed renamable $r1l, renamable $r1l, 14, 8, implicit $cc
18+
$r14l = COPY killed renamable $r14h
19+
$r14d = LGFR $r14l
20+
Return implicit $r14d
21+
...

0 commit comments

Comments
 (0)