Skip to content

Commit c4690b0

Browse files
author
Esme-Yi
committed
[PowerPC] Put the CR field in low bits of GRC during copying CRRC to GRC.
Summary: How we copying the CRRC to GRC is using a single MFOCRF to copy the contents of CR field n (CR bits 4×n+32:4×n+35) into bits 4×n+32:4×n+35 of register GRC. That’s not correct because we expect the value of destination register equals to source so we have to put the the contents of CR field in the lowest 4 bits. This patch adds a RLWINM after MFOCRF to achieve that. The problem came up when adding builtins for xvtdivdp, xvtdivsp, xvtsqrtdp, xvtsqrtsp, as posted in D88278. We need to move the outputs (in CR register) to GRC. However outputs of these instructions may not in a fixed CR# register, so we can’t directly add a rotation instruction in the .td patterns, but need to wait until the CR register is determined. Then we confirmed this should be a bug in POST-RA PSEUDO PASS. Reviewed By: nemanjai, shchenz Differential Revision: https://reviews.llvm.org/D88274
1 parent 82453e7 commit c4690b0

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

llvm/lib/Target/PowerPC/PPCInstrHTM.td

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,8 @@ def : Pat<(int_ppc_tsuspend),
164164
(TSR 0)>;
165165

166166
def : Pat<(i64 (int_ppc_ttest)),
167-
(RLDICL (i64 (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
168-
(TABORTWCI 0, (LI 0), 0), sub_32)),
169-
36, 28)>;
167+
(i64 (INSERT_SUBREG
168+
(i64 (IMPLICIT_DEF)), (TABORTWCI 0, (LI 0), 0), sub_32))>;
170169

171170
} // [HasHTM]
172171

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,14 +1272,22 @@ void PPCInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
12721272
.addImm(31);
12731273
return;
12741274
} else if (PPC::CRRCRegClass.contains(SrcReg) &&
1275-
PPC::G8RCRegClass.contains(DestReg)) {
1276-
BuildMI(MBB, I, DL, get(PPC::MFOCRF8), DestReg).addReg(SrcReg);
1277-
getKillRegState(KillSrc);
1278-
return;
1279-
} else if (PPC::CRRCRegClass.contains(SrcReg) &&
1280-
PPC::GPRCRegClass.contains(DestReg)) {
1281-
BuildMI(MBB, I, DL, get(PPC::MFOCRF), DestReg).addReg(SrcReg);
1275+
(PPC::G8RCRegClass.contains(DestReg) ||
1276+
PPC::GPRCRegClass.contains(DestReg))) {
1277+
bool Is64Bit = PPC::G8RCRegClass.contains(DestReg);
1278+
unsigned MvCode = Is64Bit ? PPC::MFOCRF8 : PPC::MFOCRF;
1279+
unsigned ShCode = Is64Bit ? PPC::RLWINM8 : PPC::RLWINM;
1280+
unsigned CRNum = TRI->getEncodingValue(SrcReg);
1281+
BuildMI(MBB, I, DL, get(MvCode), DestReg).addReg(SrcReg);
12821282
getKillRegState(KillSrc);
1283+
if (CRNum == 7)
1284+
return;
1285+
// Shift the CR bits to make the CR field in the lowest 4 bits of GRC.
1286+
BuildMI(MBB, I, DL, get(ShCode), DestReg)
1287+
.addReg(DestReg, RegState::Kill)
1288+
.addImm(CRNum * 4 + 4)
1289+
.addImm(28)
1290+
.addImm(31);
12831291
return;
12841292
} else if (PPC::G8RCRegClass.contains(SrcReg) &&
12851293
PPC::VSFRCRegClass.contains(DestReg)) {

llvm/test/CodeGen/PowerPC/htm-ttest.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define dso_local void @main() #0 {
88
; CHECK-NEXT: li 3, 0
99
; CHECK-NEXT: tabortwci. 0, 3, 0
1010
; CHECK-NEXT: mfocrf 3, 128
11-
; CHECK-NEXT: rldicl 3, 3, 36, 28
11+
; CHECK-NEXT: srwi 3, 3, 28
1212
; CHECK-NEXT: rlwinm. 3, 3, 31, 30, 31
1313
; CHECK-NEXT: beqlr+ 0
1414
; CHECK-NEXT: # %bb.1:

0 commit comments

Comments
 (0)