summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/PowerPC
diff options
context:
space:
mode:
authorZheng Chen <czhengsz@cn.ibm.com>2020-01-08 20:54:15 -0500
committerZheng Chen <czhengsz@cn.ibm.com>2020-01-08 20:59:08 -0500
commit26ba160d47220a0bce75b1f491bf6e262edf69fa (patch)
tree4478701a3b6d162d02202f2450efdd62a7b02468 /llvm/lib/Target/PowerPC
parent338a601612ca36e112b14f622eb310985b93192a (diff)
downloadbcm5719-llvm-26ba160d47220a0bce75b1f491bf6e262edf69fa.tar.gz
bcm5719-llvm-26ba160d47220a0bce75b1f491bf6e262edf69fa.zip
[PowerPC] when folding rlwinm+rlwinm. to andi., we should use first rlwinm
input reg. %2:gprc = RLWINM %1:gprc, 27, 5, 10 %3:gprc = RLWINM_rec %2:gprc, 8, 5, 10, implicit-def $cr0 ==> %3:gprc = ANDI_rec %1, 0, implicit-def $cr0 we should use %1 instead of %2 as ANDI_rec input. Reviewed By: steven.zhang Differential Revision: https://reviews.llvm.org/D71885
Diffstat (limited to 'llvm/lib/Target/PowerPC')
-rw-r--r--llvm/lib/Target/PowerPC/PPCMIPeephole.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
index 1b67e1e55bf..74192cb20cd 100644
--- a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
+++ b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
@@ -897,6 +897,8 @@ bool PPCMIPeephole::simplifyCode(void) {
bool Is64Bit = (MI.getOpcode() == PPC::RLWINM8 ||
MI.getOpcode() == PPC::RLWINM8_rec);
+ Simplified = true;
+
LLVM_DEBUG(dbgs() << "Replace Instr: ");
LLVM_DEBUG(MI.dump());
@@ -913,9 +915,14 @@ bool PPCMIPeephole::simplifyCode(void) {
MI.RemoveOperand(3);
MI.getOperand(2).setImm(0);
MI.setDesc(TII->get(Is64Bit ? PPC::ANDI8_rec : PPC::ANDI_rec));
+ MI.getOperand(1).setReg(SrcMI->getOperand(1).getReg());
+ if (SrcMI->getOperand(1).isKill()) {
+ MI.getOperand(1).setIsKill(true);
+ SrcMI->getOperand(1).setIsKill(false);
+ } else
+ // About to replace MI.getOperand(1), clear its kill flag.
+ MI.getOperand(1).setIsKill(false);
}
- Simplified = true;
- NumRotatesCollapsed++;
LLVM_DEBUG(dbgs() << "With: ");
LLVM_DEBUG(MI.dump());
@@ -925,16 +932,7 @@ bool PPCMIPeephole::simplifyCode(void) {
// than NewME. Otherwise we get a 64 bit value after folding, but MI
// return a 32 bit value.
- // If FoldingReg has only one use and it it not RLWINM_rec and
- // RLWINM8_rec, safe to delete its def SrcMI. Otherwise keep it.
- if (MRI->hasOneNonDBGUse(FoldingReg) &&
- (SrcMI->getOpcode() == PPC::RLWINM ||
- SrcMI->getOpcode() == PPC::RLWINM8)) {
- ToErase = SrcMI;
- LLVM_DEBUG(dbgs() << "Delete dead instruction: ");
- LLVM_DEBUG(SrcMI->dump());
- }
-
+ Simplified = true;
LLVM_DEBUG(dbgs() << "Converting Instr: ");
LLVM_DEBUG(MI.dump());
@@ -953,12 +951,20 @@ bool PPCMIPeephole::simplifyCode(void) {
// About to replace MI.getOperand(1), clear its kill flag.
MI.getOperand(1).setIsKill(false);
- Simplified = true;
- NumRotatesCollapsed++;
-
LLVM_DEBUG(dbgs() << "To: ");
LLVM_DEBUG(MI.dump());
}
+ if (Simplified) {
+ // If FoldingReg has no non-debug use and it has no implicit def (it
+ // is not RLWINMO or RLWINM8o), it's safe to delete its def SrcMI.
+ // Otherwise keep it.
+ ++NumRotatesCollapsed;
+ if (MRI->use_nodbg_empty(FoldingReg) && !SrcMI->hasImplicitDef()) {
+ ToErase = SrcMI;
+ LLVM_DEBUG(dbgs() << "Delete dead instruction: ");
+ LLVM_DEBUG(SrcMI->dump());
+ }
+ }
break;
}
}
OpenPOWER on IntegriCloud