Skip to content

Commit 2ea7210

Browse files
committed
Revert "[PowerPC] Extend folding RLWINM + RLWINM to post-RA."
This reverts commit 1c0941e.
1 parent fa3693a commit 2ea7210

File tree

6 files changed

+22
-235
lines changed

6 files changed

+22
-235
lines changed

llvm/lib/Target/PowerPC/PPCInstrInfo.cpp

+18-59
Original file line numberDiff line numberDiff line change
@@ -3244,64 +3244,18 @@ bool PPCInstrInfo::convertToImmediateForm(MachineInstr &MI,
32443244
return false;
32453245
}
32463246

3247-
// This function tries to combine two RLWINMs. We not only perform such
3248-
// optimization in SSA, but also after RA, since some RLWINM is generated after
3249-
// RA.
3250-
bool PPCInstrInfo::simplifyRotateAndMaskInstr(MachineInstr &MI,
3251-
MachineInstr *&ToErase) const {
3252-
bool Is64Bit = false;
3253-
switch (MI.getOpcode()) {
3254-
case PPC::RLWINM:
3255-
case PPC::RLWINM_rec:
3256-
break;
3257-
case PPC::RLWINM8:
3258-
case PPC::RLWINM8_rec:
3259-
Is64Bit = true;
3260-
break;
3261-
default:
3262-
return false;
3263-
}
3247+
bool PPCInstrInfo::combineRLWINM(MachineInstr &MI,
3248+
MachineInstr **ToErase) const {
32643249
MachineRegisterInfo *MRI = &MI.getParent()->getParent()->getRegInfo();
3265-
Register FoldingReg = MI.getOperand(1).getReg();
3266-
MachineInstr *SrcMI = nullptr;
3267-
bool CanErase = false;
3268-
bool OtherIntermediateUse = true;
3269-
if (MRI->isSSA()) {
3270-
if (!Register::isVirtualRegister(FoldingReg))
3271-
return false;
3272-
SrcMI = MRI->getVRegDef(FoldingReg);
3273-
} else {
3274-
SrcMI = getDefMIPostRA(FoldingReg, MI, OtherIntermediateUse);
3275-
}
3276-
if (!SrcMI)
3250+
unsigned FoldingReg = MI.getOperand(1).getReg();
3251+
if (!Register::isVirtualRegister(FoldingReg))
32773252
return false;
3278-
// TODO: The pairs of RLWINM8(RLWINM) or RLWINM(RLWINM8) never occur before
3279-
// RA, but after RA. And We can fold RLWINM8(RLWINM) -> RLWINM8, or
3280-
// RLWINM(RLWINM8) -> RLWINM.
3281-
switch (SrcMI->getOpcode()) {
3282-
case PPC::RLWINM:
3283-
case PPC::RLWINM_rec:
3284-
if (Is64Bit)
3285-
return false;
3286-
break;
3287-
case PPC::RLWINM8:
3288-
case PPC::RLWINM8_rec:
3289-
if (!Is64Bit)
3290-
return false;
3291-
break;
3292-
default:
3253+
MachineInstr *SrcMI = MRI->getVRegDef(FoldingReg);
3254+
if (SrcMI->getOpcode() != PPC::RLWINM &&
3255+
SrcMI->getOpcode() != PPC::RLWINM_rec &&
3256+
SrcMI->getOpcode() != PPC::RLWINM8 &&
3257+
SrcMI->getOpcode() != PPC::RLWINM8_rec)
32933258
return false;
3294-
}
3295-
if (MRI->isSSA()) {
3296-
CanErase = !SrcMI->hasImplicitDef() && MRI->hasOneNonDBGUse(FoldingReg);
3297-
} else {
3298-
CanErase = !OtherIntermediateUse && MI.getOperand(1).isKill() &&
3299-
!SrcMI->hasImplicitDef();
3300-
// In post-RA, if SrcMI also defines the register to be forwarded, we can
3301-
// only do the folding if SrcMI is going to be erased.
3302-
if (!CanErase && SrcMI->definesRegister(SrcMI->getOperand(1).getReg()))
3303-
return false;
3304-
}
33053259
assert((MI.getOperand(2).isImm() && MI.getOperand(3).isImm() &&
33063260
MI.getOperand(4).isImm() && SrcMI->getOperand(2).isImm() &&
33073261
SrcMI->getOperand(3).isImm() && SrcMI->getOperand(4).isImm()) &&
@@ -3312,6 +3266,7 @@ bool PPCInstrInfo::simplifyRotateAndMaskInstr(MachineInstr &MI,
33123266
uint64_t MBMI = MI.getOperand(3).getImm();
33133267
uint64_t MESrc = SrcMI->getOperand(4).getImm();
33143268
uint64_t MEMI = MI.getOperand(4).getImm();
3269+
33153270
assert((MEMI < 32 && MESrc < 32 && MBMI < 32 && MBSrc < 32) &&
33163271
"Invalid PPC::RLWINM Instruction!");
33173272
// If MBMI is bigger than MEMI, we always can not get run of ones.
@@ -3355,6 +3310,8 @@ bool PPCInstrInfo::simplifyRotateAndMaskInstr(MachineInstr &MI,
33553310

33563311
// If final mask is 0, MI result should be 0 too.
33573312
if (FinalMask.isNullValue()) {
3313+
bool Is64Bit =
3314+
(MI.getOpcode() == PPC::RLWINM8 || MI.getOpcode() == PPC::RLWINM8_rec);
33583315
Simplified = true;
33593316
LLVM_DEBUG(dbgs() << "Replace Instr: ");
33603317
LLVM_DEBUG(MI.dump());
@@ -3412,10 +3369,12 @@ bool PPCInstrInfo::simplifyRotateAndMaskInstr(MachineInstr &MI,
34123369
LLVM_DEBUG(dbgs() << "To: ");
34133370
LLVM_DEBUG(MI.dump());
34143371
}
3415-
if (Simplified && CanErase) {
3416-
// If SrcMI has no implicit def, and FoldingReg has no non-debug use or
3417-
// its flag is "killed", it's safe to delete SrcMI. Otherwise keep it.
3418-
ToErase = SrcMI;
3372+
if (Simplified & MRI->use_nodbg_empty(FoldingReg) &&
3373+
!SrcMI->hasImplicitDef()) {
3374+
// If FoldingReg has no non-debug use and it has no implicit def (it
3375+
// is not RLWINMO or RLWINM8o), it's safe to delete its def SrcMI.
3376+
// Otherwise keep it.
3377+
*ToErase = SrcMI;
34193378
LLVM_DEBUG(dbgs() << "Delete dead instruction: ");
34203379
LLVM_DEBUG(SrcMI->dump());
34213380
}

llvm/lib/Target/PowerPC/PPCInstrInfo.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,7 @@ class PPCInstrInfo : public PPCGenInstrInfo {
585585
bool convertToImmediateForm(MachineInstr &MI,
586586
MachineInstr **KilledDef = nullptr) const;
587587
bool foldFrameOffset(MachineInstr &MI) const;
588-
bool simplifyRotateAndMaskInstr(MachineInstr &MI,
589-
MachineInstr *&ToErase) const;
588+
bool combineRLWINM(MachineInstr &MI, MachineInstr **ToErase = nullptr) const;
590589
bool isADDIInstrEligibleForFolding(MachineInstr &ADDIMI, int64_t &Imm) const;
591590
bool isADDInstrEligibleForFolding(MachineInstr &ADDMI) const;
592591
bool isImmInstrEligibleForFolding(MachineInstr &MI, unsigned &BaseReg,

llvm/lib/Target/PowerPC/PPCMIPeephole.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ bool PPCMIPeephole::simplifyCode(void) {
987987
case PPC::RLWINM_rec:
988988
case PPC::RLWINM8:
989989
case PPC::RLWINM8_rec: {
990-
Simplified = TII->simplifyRotateAndMaskInstr(MI, ToErase);
990+
Simplified = TII->combineRLWINM(MI, &ToErase);
991991
if (Simplified)
992992
++NumRotatesCollapsed;
993993
break;

llvm/lib/Target/PowerPC/PPCPreEmitPeephole.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ STATISTIC(NumberOfSelfCopies,
3737
"Number of self copy instructions eliminated");
3838
STATISTIC(NumFrameOffFoldInPreEmit,
3939
"Number of folding frame offset by using r+r in pre-emit peephole");
40-
STATISTIC(NumRotateInstrFoldInPreEmit,
41-
"Number of folding Rotate instructions in pre-emit peephole");
4240

4341
static cl::opt<bool>
4442
EnablePCRelLinkerOpt("ppc-pcrel-linker-opt", cl::Hidden, cl::init(true),
@@ -474,13 +472,6 @@ static bool hasPCRelativeForm(MachineInstr &Use) {
474472
LLVM_DEBUG(dbgs() << "Frame offset folding by using index form: ");
475473
LLVM_DEBUG(MI.dump());
476474
}
477-
MachineInstr *ToErase = nullptr;
478-
if (TII->simplifyRotateAndMaskInstr(MI, ToErase)) {
479-
Changed = true;
480-
NumRotateInstrFoldInPreEmit++;
481-
if (ToErase)
482-
InstrsToErase.push_back(ToErase);
483-
}
484475
}
485476

486477
// Eliminate conditional branch based on a constant CR bit by

llvm/test/CodeGen/PowerPC/fold-rlwinm-after-ra.mir

-163
This file was deleted.

llvm/test/CodeGen/PowerPC/vsx_builtins.ll

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ define i32 @xvtdivdp_shift(<2 x double> %a, <2 x double> %b) {
131131
; CHECK: # %bb.0: # %entry
132132
; CHECK-NEXT: xvtdivdp cr0, v2, v3
133133
; CHECK-NEXT: mfocrf r3, 128
134-
; CHECK-NEXT: li r3, 0
134+
; CHECK-NEXT: srwi r3, r3, 28
135+
; CHECK-NEXT: rlwinm r3, r3, 28, 31, 31
135136
; CHECK-NEXT: blr
136137
entry:
137138
%0 = tail call i32 @llvm.ppc.vsx.xvtdivdp(<2 x double> %a, <2 x double> %b)

0 commit comments

Comments
 (0)