aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
diff options
context:
space:
mode:
authorzhijian lin <zhijian@ca.ibm.com>2024-10-31 15:49:36 -0400
committerGitHub <noreply@github.com>2024-10-31 15:49:36 -0400
commit674574d25cc35010dbb0b12b01e8beeaddf20a3f (patch)
tree76991fbcf9614114ab46de94d88c48545b3df33a /llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
parent913cd11f941bd22617b86048afbcab94be30816a (diff)
downloadllvm-674574d25cc35010dbb0b12b01e8beeaddf20a3f.zip
llvm-674574d25cc35010dbb0b12b01e8beeaddf20a3f.tar.gz
llvm-674574d25cc35010dbb0b12b01e8beeaddf20a3f.tar.bz2
Promote 32bit pseudo instr that infer extsw removal to 64bit in PPCMIPeephole (#85451)
Fixes: https://github.com/llvm/llvm-project/issues/71030 Bug only happens in 64bit involving spills. Since we don't know when the spill will happen, all instructions in the chain used to deduce sign extension for eliminating 'extsw' will need to be promoted to 64-bit pseudo instructions. The following instruction will promoted in PPCMIPeepholes: EXTSH, LHA, ISEL to EXTSH8, LHA8, ISEL8
Diffstat (limited to 'llvm/lib/Target/PowerPC/PPCMIPeephole.cpp')
-rw-r--r--llvm/lib/Target/PowerPC/PPCMIPeephole.cpp11
1 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
index b8abee7..b762cac8 100644
--- a/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
+++ b/llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
@@ -1053,7 +1053,16 @@ bool PPCMIPeephole::simplifyCode() {
} else if (MI.getOpcode() == PPC::EXTSW_32_64 &&
TII->isSignExtended(NarrowReg, MRI)) {
// We can eliminate EXTSW if the input is known to be already
- // sign-extended.
+ // sign-extended. However, we are not sure whether a spill will occur
+ // during register allocation. If there is no promotion, it will use
+ // 'stw' instead of 'std', and 'lwz' instead of 'ld' when spilling,
+ // since the register class is 32-bits. Consequently, the high 32-bit
+ // information will be lost. Therefore, all these instructions in the
+ // chain used to deduce sign extension to eliminate the 'extsw' will
+ // need to be promoted to 64-bit pseudo instructions when the 'extsw'
+ // is eliminated.
+ TII->promoteInstr32To64ForElimEXTSW(NarrowReg, MRI, 0, LV);
+
LLVM_DEBUG(dbgs() << "Removing redundant sign-extension\n");
Register TmpReg =
MF->getRegInfo().createVirtualRegister(&PPC::G8RCRegClass);