[llvm] r335989 - [mips] Support shrink-wrapping
Petar Jovanovic via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 29 09:37:16 PDT 2018
Author: petarj
Date: Fri Jun 29 09:37:16 2018
New Revision: 335989
URL: http://llvm.org/viewvc/llvm-project?rev=335989&view=rev
Log:
[mips] Support shrink-wrapping
Except for -O0, it's enabled by default.
Patch by Vladimir Stefanovic.
Differential Revision: https://reviews.llvm.org/D47947
Added:
llvm/trunk/test/CodeGen/Mips/shrink-wrapping.ll
Modified:
llvm/trunk/lib/Target/Mips/Mips16FrameLowering.cpp
llvm/trunk/lib/Target/Mips/MipsFrameLowering.h
llvm/trunk/lib/Target/Mips/MipsSEFrameLowering.cpp
llvm/trunk/test/CodeGen/Mips/blez_bgez.ll
llvm/trunk/test/CodeGen/Mips/brdelayslot.ll
Modified: llvm/trunk/lib/Target/Mips/Mips16FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/Mips16FrameLowering.cpp?rev=335989&r1=335988&r2=335989&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/Mips16FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/Mips/Mips16FrameLowering.cpp Fri Jun 29 09:37:16 2018
@@ -42,7 +42,6 @@ Mips16FrameLowering::Mips16FrameLowering
void Mips16FrameLowering::emitPrologue(MachineFunction &MF,
MachineBasicBlock &MBB) const {
- assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
MachineFrameInfo &MFI = MF.getFrameInfo();
const Mips16InstrInfo &TII =
*static_cast<const Mips16InstrInfo *>(STI.getInstrInfo());
@@ -92,11 +91,11 @@ void Mips16FrameLowering::emitPrologue(M
void Mips16FrameLowering::emitEpilogue(MachineFunction &MF,
MachineBasicBlock &MBB) const {
- MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
+ MachineBasicBlock::iterator MBBI = MBB.getFirstTerminator();
MachineFrameInfo &MFI = MF.getFrameInfo();
const Mips16InstrInfo &TII =
*static_cast<const Mips16InstrInfo *>(STI.getInstrInfo());
- DebugLoc dl = MBBI->getDebugLoc();
+ DebugLoc dl = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
uint64_t StackSize = MFI.getStackSize();
if (!StackSize)
@@ -117,7 +116,6 @@ spillCalleeSavedRegisters(MachineBasicBl
const std::vector<CalleeSavedInfo> &CSI,
const TargetRegisterInfo *TRI) const {
MachineFunction *MF = MBB.getParent();
- MachineBasicBlock *EntryBlock = &MF->front();
//
// Registers RA, S0,S1 are the callee saved registers and they
@@ -134,7 +132,7 @@ spillCalleeSavedRegisters(MachineBasicBl
bool IsRAAndRetAddrIsTaken = (Reg == Mips::RA)
&& MF->getFrameInfo().isReturnAddressTaken();
if (!IsRAAndRetAddrIsTaken)
- EntryBlock->addLiveIn(Reg);
+ MBB.addLiveIn(Reg);
}
return true;
Modified: llvm/trunk/lib/Target/Mips/MipsFrameLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsFrameLowering.h?rev=335989&r1=335988&r2=335989&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsFrameLowering.h (original)
+++ llvm/trunk/lib/Target/Mips/MipsFrameLowering.h Fri Jun 29 09:37:16 2018
@@ -36,6 +36,10 @@ public:
bool isFPCloseToIncomingSP() const override { return false; }
+ bool enableShrinkWrapping(const MachineFunction &MF) const override {
+ return true;
+ }
+
MachineBasicBlock::iterator
eliminateCallFramePseudoInstr(MachineFunction &MF,
MachineBasicBlock &MBB,
Modified: llvm/trunk/lib/Target/Mips/MipsSEFrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MipsSEFrameLowering.cpp?rev=335989&r1=335988&r2=335989&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MipsSEFrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MipsSEFrameLowering.cpp Fri Jun 29 09:37:16 2018
@@ -394,7 +394,6 @@ MipsSEFrameLowering::MipsSEFrameLowering
void MipsSEFrameLowering::emitPrologue(MachineFunction &MF,
MachineBasicBlock &MBB) const {
- assert(&MF.front() == &MBB && "Shrink-wrapping not yet supported");
MachineFrameInfo &MFI = MF.getFrameInfo();
MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
@@ -682,7 +681,7 @@ void MipsSEFrameLowering::emitInterruptP
void MipsSEFrameLowering::emitEpilogue(MachineFunction &MF,
MachineBasicBlock &MBB) const {
- MachineBasicBlock::iterator MBBI = MBB.getLastNonDebugInstr();
+ MachineBasicBlock::iterator MBBI = MBB.getFirstTerminator();
MachineFrameInfo &MFI = MF.getFrameInfo();
MipsFunctionInfo *MipsFI = MF.getInfo<MipsFunctionInfo>();
@@ -691,7 +690,7 @@ void MipsSEFrameLowering::emitEpilogue(M
const MipsRegisterInfo &RegInfo =
*static_cast<const MipsRegisterInfo *>(STI.getRegisterInfo());
- DebugLoc DL = MBBI->getDebugLoc();
+ DebugLoc DL = MBBI != MBB.end() ? MBBI->getDebugLoc() : DebugLoc();
MipsABIInfo ABI = STI.getABI();
unsigned SP = ABI.GetStackPtr();
unsigned FP = ABI.GetFramePtr();
@@ -790,7 +789,6 @@ spillCalleeSavedRegisters(MachineBasicBl
const std::vector<CalleeSavedInfo> &CSI,
const TargetRegisterInfo *TRI) const {
MachineFunction *MF = MBB.getParent();
- MachineBasicBlock *EntryBlock = &MF->front();
const TargetInstrInfo &TII = *STI.getInstrInfo();
for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
@@ -803,7 +801,7 @@ spillCalleeSavedRegisters(MachineBasicBl
bool IsRAAndRetAddrIsTaken = (Reg == Mips::RA || Reg == Mips::RA_64)
&& MF->getFrameInfo().isReturnAddressTaken();
if (!IsRAAndRetAddrIsTaken)
- EntryBlock->addLiveIn(Reg);
+ MBB.addLiveIn(Reg);
// ISRs require HI/LO to be spilled into kernel registers to be then
// spilled to the stack frame.
@@ -828,7 +826,7 @@ spillCalleeSavedRegisters(MachineBasicBl
// Insert the spill to the stack frame.
bool IsKill = !IsRAAndRetAddrIsTaken;
const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg);
- TII.storeRegToStackSlot(*EntryBlock, MI, Reg, IsKill,
+ TII.storeRegToStackSlot(MBB, MI, Reg, IsKill,
CSI[i].getFrameIdx(), RC, TRI);
}
Modified: llvm/trunk/test/CodeGen/Mips/blez_bgez.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/blez_bgez.ll?rev=335989&r1=335988&r2=335989&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/blez_bgez.ll (original)
+++ llvm/trunk/test/CodeGen/Mips/blez_bgez.ll Fri Jun 29 09:37:16 2018
@@ -1,5 +1,5 @@
-; RUN: llc -march=mipsel < %s | FileCheck %s
-; RUN: llc -march=mips64el < %s | FileCheck %s
+; RUN: llc -march=mipsel -enable-shrink-wrap=false < %s | FileCheck %s
+; RUN: llc -march=mips64el -enable-shrink-wrap=false < %s | FileCheck %s
; CHECK-LABEL: test_blez:
; CHECK: blez ${{[0-9]+}}, {{\$|\.L}}BB
Modified: llvm/trunk/test/CodeGen/Mips/brdelayslot.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/brdelayslot.ll?rev=335989&r1=335988&r2=335989&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/brdelayslot.ll (original)
+++ llvm/trunk/test/CodeGen/Mips/brdelayslot.ll Fri Jun 29 09:37:16 2018
@@ -6,6 +6,7 @@
; RUN: llc -march=mipsel -disable-mips-df-forward-search=false \
; RUN: -relocation-model=static < %s | FileCheck %s -check-prefix=FORWARD
; RUN: llc -march=mipsel -disable-mips-df-backward-search -relocation-model=pic \
+; RUN: -enable-shrink-wrap=false \
; RUN: -disable-mips-df-succbb-search=false -disable-preheader-prot=true < %s | \
; RUN: FileCheck %s -check-prefix=SUCCBB
Added: llvm/trunk/test/CodeGen/Mips/shrink-wrapping.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/Mips/shrink-wrapping.ll?rev=335989&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/Mips/shrink-wrapping.ll (added)
+++ llvm/trunk/test/CodeGen/Mips/shrink-wrapping.ll Fri Jun 29 09:37:16 2018
@@ -0,0 +1,391 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+
+; RUN: llc -mtriple=mips-unknown-linux-gnu -enable-shrink-wrap=true \
+; RUN: -relocation-model=static < %s | \
+; RUN: FileCheck %s -check-prefix=SHRINK-WRAP-STATIC
+
+; RUN: llc -mtriple=mips-unknown-linux-gnu -enable-shrink-wrap=false \
+; RUN: -relocation-model=static < %s | \
+; RUN: FileCheck %s -check-prefix=NO-SHRINK-WRAP-STATIC
+
+; RUN: llc -mtriple=mips-unknown-linux-gnu -enable-shrink-wrap=true \
+; RUN: -relocation-model=pic < %s | \
+; RUN: FileCheck %s -check-prefix=SHRINK-WRAP-PIC
+
+; RUN: llc -mtriple=mips-unknown-linux-gnu -enable-shrink-wrap=false \
+; RUN: -relocation-model=pic < %s | \
+; RUN: FileCheck %s -check-prefix=NO-SHRINK-WRAP-PIC
+
+; RUN: llc -mtriple=mips64-unknown-linux-gnu -enable-shrink-wrap=true \
+; RUN: -relocation-model=static < %s | \
+; RUN: FileCheck %s -check-prefix=SHRINK-WRAP-64-STATIC
+
+; RUN: llc -mtriple=mips64-unknown-linux-gnu -enable-shrink-wrap=false \
+; RUN: -relocation-model=static < %s | \
+; RUN: FileCheck %s -check-prefix=NO-SHRINK-WRAP-64-STATIC
+
+; RUN: llc -mtriple=mips64-unknown-linux-gnu -enable-shrink-wrap=true \
+; RUN: -relocation-model=pic < %s | \
+; RUN: FileCheck %s -check-prefix=SHRINK-WRAP-64-PIC
+
+; RUN: llc -mtriple=mips64-unknown-linux-gnu -enable-shrink-wrap=false \
+; RUN: -relocation-model=pic < %s | \
+; RUN: FileCheck %s -check-prefix=NO-SHRINK-WRAP-64-PIC
+
+declare void @f(i32 signext)
+
+define i32 @foo(i32 signext %a) {
+; SHRINK-WRAP-STATIC-LABEL: foo:
+; SHRINK-WRAP-STATIC: # %bb.0: # %entry
+; SHRINK-WRAP-STATIC-NEXT: beqz $4, $BB0_2
+; SHRINK-WRAP-STATIC-NEXT: nop
+; SHRINK-WRAP-STATIC-NEXT: # %bb.1: # %if.end
+; SHRINK-WRAP-STATIC-NEXT: addiu $sp, $sp, -24
+; SHRINK-WRAP-STATIC-NEXT: .cfi_def_cfa_offset 24
+; SHRINK-WRAP-STATIC-NEXT: sw $ra, 20($sp) # 4-byte Folded Spill
+; SHRINK-WRAP-STATIC-NEXT: .cfi_offset 31, -4
+; SHRINK-WRAP-STATIC-NEXT: jal f
+; SHRINK-WRAP-STATIC-NEXT: addiu $4, $4, 1
+; SHRINK-WRAP-STATIC-NEXT: lw $ra, 20($sp) # 4-byte Folded Reload
+; SHRINK-WRAP-STATIC-NEXT: addiu $sp, $sp, 24
+; SHRINK-WRAP-STATIC-NEXT: $BB0_2: # %return
+; SHRINK-WRAP-STATIC-NEXT: jr $ra
+; SHRINK-WRAP-STATIC-NEXT: addiu $2, $zero, 0
+;
+; NO-SHRINK-WRAP-STATIC-LABEL: foo:
+; NO-SHRINK-WRAP-STATIC: # %bb.0: # %entry
+; NO-SHRINK-WRAP-STATIC-NEXT: addiu $sp, $sp, -24
+; NO-SHRINK-WRAP-STATIC-NEXT: .cfi_def_cfa_offset 24
+; NO-SHRINK-WRAP-STATIC-NEXT: sw $ra, 20($sp) # 4-byte Folded Spill
+; NO-SHRINK-WRAP-STATIC-NEXT: .cfi_offset 31, -4
+; NO-SHRINK-WRAP-STATIC-NEXT: beqz $4, $BB0_2
+; NO-SHRINK-WRAP-STATIC-NEXT: nop
+; NO-SHRINK-WRAP-STATIC-NEXT: # %bb.1: # %if.end
+; NO-SHRINK-WRAP-STATIC-NEXT: jal f
+; NO-SHRINK-WRAP-STATIC-NEXT: addiu $4, $4, 1
+; NO-SHRINK-WRAP-STATIC-NEXT: $BB0_2: # %return
+; NO-SHRINK-WRAP-STATIC-NEXT: addiu $2, $zero, 0
+; NO-SHRINK-WRAP-STATIC-NEXT: lw $ra, 20($sp) # 4-byte Folded Reload
+; NO-SHRINK-WRAP-STATIC-NEXT: jr $ra
+; NO-SHRINK-WRAP-STATIC-NEXT: addiu $sp, $sp, 24
+;
+; SHRINK-WRAP-PIC-LABEL: foo:
+; SHRINK-WRAP-PIC: # %bb.0: # %entry
+; SHRINK-WRAP-PIC-NEXT: lui $2, %hi(_gp_disp)
+; SHRINK-WRAP-PIC-NEXT: addiu $2, $2, %lo(_gp_disp)
+; SHRINK-WRAP-PIC-NEXT: beqz $4, $BB0_2
+; SHRINK-WRAP-PIC-NEXT: addu $gp, $2, $25
+; SHRINK-WRAP-PIC-NEXT: # %bb.1: # %if.end
+; SHRINK-WRAP-PIC-NEXT: addiu $sp, $sp, -24
+; SHRINK-WRAP-PIC-NEXT: .cfi_def_cfa_offset 24
+; SHRINK-WRAP-PIC-NEXT: sw $ra, 20($sp) # 4-byte Folded Spill
+; SHRINK-WRAP-PIC-NEXT: .cfi_offset 31, -4
+; SHRINK-WRAP-PIC-NEXT: lw $25, %call16(f)($gp)
+; SHRINK-WRAP-PIC-NEXT: jalr $25
+; SHRINK-WRAP-PIC-NEXT: addiu $4, $4, 1
+; SHRINK-WRAP-PIC-NEXT: lw $ra, 20($sp) # 4-byte Folded Reload
+; SHRINK-WRAP-PIC-NEXT: addiu $sp, $sp, 24
+; SHRINK-WRAP-PIC-NEXT: $BB0_2: # %return
+; SHRINK-WRAP-PIC-NEXT: jr $ra
+; SHRINK-WRAP-PIC-NEXT: addiu $2, $zero, 0
+;
+; NO-SHRINK-WRAP-PIC-LABEL: foo:
+; NO-SHRINK-WRAP-PIC: # %bb.0: # %entry
+; NO-SHRINK-WRAP-PIC-NEXT: lui $2, %hi(_gp_disp)
+; NO-SHRINK-WRAP-PIC-NEXT: addiu $2, $2, %lo(_gp_disp)
+; NO-SHRINK-WRAP-PIC-NEXT: addiu $sp, $sp, -24
+; NO-SHRINK-WRAP-PIC-NEXT: .cfi_def_cfa_offset 24
+; NO-SHRINK-WRAP-PIC-NEXT: sw $ra, 20($sp) # 4-byte Folded Spill
+; NO-SHRINK-WRAP-PIC-NEXT: .cfi_offset 31, -4
+; NO-SHRINK-WRAP-PIC-NEXT: beqz $4, $BB0_2
+; NO-SHRINK-WRAP-PIC-NEXT: addu $gp, $2, $25
+; NO-SHRINK-WRAP-PIC-NEXT: # %bb.1: # %if.end
+; NO-SHRINK-WRAP-PIC-NEXT: lw $25, %call16(f)($gp)
+; NO-SHRINK-WRAP-PIC-NEXT: jalr $25
+; NO-SHRINK-WRAP-PIC-NEXT: addiu $4, $4, 1
+; NO-SHRINK-WRAP-PIC-NEXT: $BB0_2: # %return
+; NO-SHRINK-WRAP-PIC-NEXT: addiu $2, $zero, 0
+; NO-SHRINK-WRAP-PIC-NEXT: lw $ra, 20($sp) # 4-byte Folded Reload
+; NO-SHRINK-WRAP-PIC-NEXT: jr $ra
+; NO-SHRINK-WRAP-PIC-NEXT: addiu $sp, $sp, 24
+;
+; SHRINK-WRAP-64-STATIC-LABEL: foo:
+; SHRINK-WRAP-64-STATIC: # %bb.0: # %entry
+; SHRINK-WRAP-64-STATIC-NEXT: beqz $4, .LBB0_2
+; SHRINK-WRAP-64-STATIC-NEXT: nop
+; SHRINK-WRAP-64-STATIC-NEXT: # %bb.1: # %if.end
+; SHRINK-WRAP-64-STATIC-NEXT: daddiu $sp, $sp, -16
+; SHRINK-WRAP-64-STATIC-NEXT: .cfi_def_cfa_offset 16
+; SHRINK-WRAP-64-STATIC-NEXT: sd $ra, 8($sp) # 8-byte Folded Spill
+; SHRINK-WRAP-64-STATIC-NEXT: .cfi_offset 31, -8
+; SHRINK-WRAP-64-STATIC-NEXT: addiu $1, $4, 1
+; SHRINK-WRAP-64-STATIC-NEXT: jal f
+; SHRINK-WRAP-64-STATIC-NEXT: sll $4, $1, 0
+; SHRINK-WRAP-64-STATIC-NEXT: ld $ra, 8($sp) # 8-byte Folded Reload
+; SHRINK-WRAP-64-STATIC-NEXT: daddiu $sp, $sp, 16
+; SHRINK-WRAP-64-STATIC-NEXT: .LBB0_2: # %return
+; SHRINK-WRAP-64-STATIC-NEXT: jr $ra
+; SHRINK-WRAP-64-STATIC-NEXT: addiu $2, $zero, 0
+;
+; NO-SHRINK-WRAP-64-STATIC-LABEL: foo:
+; NO-SHRINK-WRAP-64-STATIC: # %bb.0: # %entry
+; NO-SHRINK-WRAP-64-STATIC-NEXT: daddiu $sp, $sp, -16
+; NO-SHRINK-WRAP-64-STATIC-NEXT: .cfi_def_cfa_offset 16
+; NO-SHRINK-WRAP-64-STATIC-NEXT: sd $ra, 8($sp) # 8-byte Folded Spill
+; NO-SHRINK-WRAP-64-STATIC-NEXT: .cfi_offset 31, -8
+; NO-SHRINK-WRAP-64-STATIC-NEXT: beqz $4, .LBB0_2
+; NO-SHRINK-WRAP-64-STATIC-NEXT: nop
+; NO-SHRINK-WRAP-64-STATIC-NEXT: # %bb.1: # %if.end
+; NO-SHRINK-WRAP-64-STATIC-NEXT: addiu $1, $4, 1
+; NO-SHRINK-WRAP-64-STATIC-NEXT: jal f
+; NO-SHRINK-WRAP-64-STATIC-NEXT: sll $4, $1, 0
+; NO-SHRINK-WRAP-64-STATIC-NEXT: .LBB0_2: # %return
+; NO-SHRINK-WRAP-64-STATIC-NEXT: addiu $2, $zero, 0
+; NO-SHRINK-WRAP-64-STATIC-NEXT: ld $ra, 8($sp) # 8-byte Folded Reload
+; NO-SHRINK-WRAP-64-STATIC-NEXT: jr $ra
+; NO-SHRINK-WRAP-64-STATIC-NEXT: daddiu $sp, $sp, 16
+;
+; SHRINK-WRAP-64-PIC-LABEL: foo:
+; SHRINK-WRAP-64-PIC: # %bb.0: # %entry
+; SHRINK-WRAP-64-PIC-NEXT: lui $1, %hi(%neg(%gp_rel(foo)))
+; SHRINK-WRAP-64-PIC-NEXT: beqz $4, .LBB0_2
+; SHRINK-WRAP-64-PIC-NEXT: daddu $2, $1, $25
+; SHRINK-WRAP-64-PIC-NEXT: # %bb.1: # %if.end
+; SHRINK-WRAP-64-PIC-NEXT: daddiu $sp, $sp, -16
+; SHRINK-WRAP-64-PIC-NEXT: .cfi_def_cfa_offset 16
+; SHRINK-WRAP-64-PIC-NEXT: sd $ra, 8($sp) # 8-byte Folded Spill
+; SHRINK-WRAP-64-PIC-NEXT: sd $gp, 0($sp) # 8-byte Folded Spill
+; SHRINK-WRAP-64-PIC-NEXT: .cfi_offset 31, -8
+; SHRINK-WRAP-64-PIC-NEXT: .cfi_offset 28, -16
+; SHRINK-WRAP-64-PIC-NEXT: daddiu $gp, $2, %lo(%neg(%gp_rel(foo)))
+; SHRINK-WRAP-64-PIC-NEXT: addiu $1, $4, 1
+; SHRINK-WRAP-64-PIC-NEXT: ld $25, %call16(f)($gp)
+; SHRINK-WRAP-64-PIC-NEXT: jalr $25
+; SHRINK-WRAP-64-PIC-NEXT: sll $4, $1, 0
+; SHRINK-WRAP-64-PIC-NEXT: ld $gp, 0($sp) # 8-byte Folded Reload
+; SHRINK-WRAP-64-PIC-NEXT: ld $ra, 8($sp) # 8-byte Folded Reload
+; SHRINK-WRAP-64-PIC-NEXT: daddiu $sp, $sp, 16
+; SHRINK-WRAP-64-PIC-NEXT: .LBB0_2: # %return
+; SHRINK-WRAP-64-PIC-NEXT: jr $ra
+; SHRINK-WRAP-64-PIC-NEXT: addiu $2, $zero, 0
+;
+; NO-SHRINK-WRAP-64-PIC-LABEL: foo:
+; NO-SHRINK-WRAP-64-PIC: # %bb.0: # %entry
+; NO-SHRINK-WRAP-64-PIC-NEXT: daddiu $sp, $sp, -16
+; NO-SHRINK-WRAP-64-PIC-NEXT: .cfi_def_cfa_offset 16
+; NO-SHRINK-WRAP-64-PIC-NEXT: sd $ra, 8($sp) # 8-byte Folded Spill
+; NO-SHRINK-WRAP-64-PIC-NEXT: sd $gp, 0($sp) # 8-byte Folded Spill
+; NO-SHRINK-WRAP-64-PIC-NEXT: .cfi_offset 31, -8
+; NO-SHRINK-WRAP-64-PIC-NEXT: .cfi_offset 28, -16
+; NO-SHRINK-WRAP-64-PIC-NEXT: lui $1, %hi(%neg(%gp_rel(foo)))
+; NO-SHRINK-WRAP-64-PIC-NEXT: beqz $4, .LBB0_2
+; NO-SHRINK-WRAP-64-PIC-NEXT: daddu $2, $1, $25
+; NO-SHRINK-WRAP-64-PIC-NEXT: # %bb.1: # %if.end
+; NO-SHRINK-WRAP-64-PIC-NEXT: daddiu $gp, $2, %lo(%neg(%gp_rel(foo)))
+; NO-SHRINK-WRAP-64-PIC-NEXT: addiu $1, $4, 1
+; NO-SHRINK-WRAP-64-PIC-NEXT: ld $25, %call16(f)($gp)
+; NO-SHRINK-WRAP-64-PIC-NEXT: jalr $25
+; NO-SHRINK-WRAP-64-PIC-NEXT: sll $4, $1, 0
+; NO-SHRINK-WRAP-64-PIC-NEXT: .LBB0_2: # %return
+; NO-SHRINK-WRAP-64-PIC-NEXT: addiu $2, $zero, 0
+; NO-SHRINK-WRAP-64-PIC-NEXT: ld $gp, 0($sp) # 8-byte Folded Reload
+; NO-SHRINK-WRAP-64-PIC-NEXT: ld $ra, 8($sp) # 8-byte Folded Reload
+; NO-SHRINK-WRAP-64-PIC-NEXT: jr $ra
+; NO-SHRINK-WRAP-64-PIC-NEXT: daddiu $sp, $sp, 16
+entry:
+ %cmp = icmp eq i32 %a, 0
+ br i1 %cmp, label %return, label %if.end
+
+if.end:
+ %add = add nsw i32 %a, 1
+ tail call void @f(i32 signext %add)
+ br label %return
+
+return:
+ ret i32 0
+}
+
+; Test that long branch expansion works correctly with shrink-wrapping enabled.
+define i32 @foo2(i32 signext %a) {
+; SHRINK-WRAP-STATIC-LABEL: foo2:
+; SHRINK-WRAP-STATIC: # %bb.0:
+; SHRINK-WRAP-STATIC-NEXT: addiu $1, $zero, 4
+; SHRINK-WRAP-STATIC-NEXT: bne $4, $1, $BB1_2
+; SHRINK-WRAP-STATIC-NEXT: nop
+; SHRINK-WRAP-STATIC-NEXT: # %bb.1:
+; SHRINK-WRAP-STATIC-NEXT: j $BB1_3
+; SHRINK-WRAP-STATIC-NEXT: nop
+; SHRINK-WRAP-STATIC-NEXT: $BB1_2: # %if.then
+; SHRINK-WRAP-STATIC-NEXT: addiu $sp, $sp, -24
+; SHRINK-WRAP-STATIC-NEXT: .cfi_def_cfa_offset 24
+; SHRINK-WRAP-STATIC-NEXT: sw $ra, 20($sp) # 4-byte Folded Spill
+; SHRINK-WRAP-STATIC-NEXT: .cfi_offset 31, -4
+; SHRINK-WRAP-STATIC-NEXT: #APP
+;
+; NO-SHRINK-WRAP-STATIC-LABEL: foo2:
+; NO-SHRINK-WRAP-STATIC: # %bb.0:
+; NO-SHRINK-WRAP-STATIC-NEXT: addiu $sp, $sp, -24
+; NO-SHRINK-WRAP-STATIC-NEXT: .cfi_def_cfa_offset 24
+; NO-SHRINK-WRAP-STATIC-NEXT: sw $ra, 20($sp) # 4-byte Folded Spill
+; NO-SHRINK-WRAP-STATIC-NEXT: .cfi_offset 31, -4
+; NO-SHRINK-WRAP-STATIC-NEXT: addiu $1, $zero, 4
+; NO-SHRINK-WRAP-STATIC-NEXT: bne $4, $1, $BB1_2
+; NO-SHRINK-WRAP-STATIC-NEXT: nop
+; NO-SHRINK-WRAP-STATIC-NEXT: # %bb.1:
+; NO-SHRINK-WRAP-STATIC-NEXT: j $BB1_3
+; NO-SHRINK-WRAP-STATIC-NEXT: nop
+; NO-SHRINK-WRAP-STATIC-NEXT: $BB1_2: # %if.then
+; NO-SHRINK-WRAP-STATIC-NEXT: #APP
+;
+; SHRINK-WRAP-PIC-LABEL: foo2:
+; SHRINK-WRAP-PIC: # %bb.0:
+; SHRINK-WRAP-PIC-NEXT: lui $2, %hi(_gp_disp)
+; SHRINK-WRAP-PIC-NEXT: addiu $2, $2, %lo(_gp_disp)
+; SHRINK-WRAP-PIC-NEXT: addiu $1, $zero, 4
+; SHRINK-WRAP-PIC-NEXT: bne $4, $1, $BB1_3
+; SHRINK-WRAP-PIC-NEXT: addu $gp, $2, $25
+; SHRINK-WRAP-PIC-NEXT: # %bb.1:
+; SHRINK-WRAP-PIC-NEXT: addiu $sp, $sp, -8
+; SHRINK-WRAP-PIC-NEXT: sw $ra, 0($sp)
+; SHRINK-WRAP-PIC-NEXT: lui $1, %hi(($BB1_4)-($BB1_2))
+; SHRINK-WRAP-PIC-NEXT: bal $BB1_2
+; SHRINK-WRAP-PIC-NEXT: addiu $1, $1, %lo(($BB1_4)-($BB1_2))
+; SHRINK-WRAP-PIC-NEXT: $BB1_2:
+; SHRINK-WRAP-PIC-NEXT: addu $1, $ra, $1
+; SHRINK-WRAP-PIC-NEXT: lw $ra, 0($sp)
+; SHRINK-WRAP-PIC-NEXT: jr $1
+; SHRINK-WRAP-PIC-NEXT: addiu $sp, $sp, 8
+; SHRINK-WRAP-PIC-NEXT: $BB1_3: # %if.then
+; SHRINK-WRAP-PIC-NEXT: addiu $sp, $sp, -24
+; SHRINK-WRAP-PIC-NEXT: .cfi_def_cfa_offset 24
+; SHRINK-WRAP-PIC-NEXT: sw $ra, 20($sp) # 4-byte Folded Spill
+; SHRINK-WRAP-PIC-NEXT: .cfi_offset 31, -4
+; SHRINK-WRAP-PIC-NEXT: #APP
+;
+; NO-SHRINK-WRAP-PIC-LABEL: foo2:
+; NO-SHRINK-WRAP-PIC: # %bb.0:
+; NO-SHRINK-WRAP-PIC-NEXT: lui $2, %hi(_gp_disp)
+; NO-SHRINK-WRAP-PIC-NEXT: addiu $2, $2, %lo(_gp_disp)
+; NO-SHRINK-WRAP-PIC-NEXT: addiu $sp, $sp, -24
+; NO-SHRINK-WRAP-PIC-NEXT: .cfi_def_cfa_offset 24
+; NO-SHRINK-WRAP-PIC-NEXT: sw $ra, 20($sp) # 4-byte Folded Spill
+; NO-SHRINK-WRAP-PIC-NEXT: .cfi_offset 31, -4
+; NO-SHRINK-WRAP-PIC-NEXT: addiu $1, $zero, 4
+; NO-SHRINK-WRAP-PIC-NEXT: bne $4, $1, $BB1_3
+; NO-SHRINK-WRAP-PIC-NEXT: addu $gp, $2, $25
+; NO-SHRINK-WRAP-PIC-NEXT: # %bb.1:
+; NO-SHRINK-WRAP-PIC-NEXT: addiu $sp, $sp, -8
+; NO-SHRINK-WRAP-PIC-NEXT: sw $ra, 0($sp)
+; NO-SHRINK-WRAP-PIC-NEXT: lui $1, %hi(($BB1_4)-($BB1_2))
+; NO-SHRINK-WRAP-PIC-NEXT: bal $BB1_2
+; NO-SHRINK-WRAP-PIC-NEXT: addiu $1, $1, %lo(($BB1_4)-($BB1_2))
+; NO-SHRINK-WRAP-PIC-NEXT: $BB1_2:
+; NO-SHRINK-WRAP-PIC-NEXT: addu $1, $ra, $1
+; NO-SHRINK-WRAP-PIC-NEXT: lw $ra, 0($sp)
+; NO-SHRINK-WRAP-PIC-NEXT: jr $1
+; NO-SHRINK-WRAP-PIC-NEXT: addiu $sp, $sp, 8
+; NO-SHRINK-WRAP-PIC-NEXT: $BB1_3: # %if.then
+; NO-SHRINK-WRAP-PIC-NEXT: #APP
+;
+; SHRINK-WRAP-64-STATIC-LABEL: foo2:
+; SHRINK-WRAP-64-STATIC: # %bb.0:
+; SHRINK-WRAP-64-STATIC-NEXT: addiu $1, $zero, 4
+; SHRINK-WRAP-64-STATIC-NEXT: bne $4, $1, .LBB1_2
+; SHRINK-WRAP-64-STATIC-NEXT: nop
+; SHRINK-WRAP-64-STATIC-NEXT: # %bb.1:
+; SHRINK-WRAP-64-STATIC-NEXT: j .LBB1_3
+; SHRINK-WRAP-64-STATIC-NEXT: nop
+; SHRINK-WRAP-64-STATIC-NEXT: .LBB1_2: # %if.then
+; SHRINK-WRAP-64-STATIC-NEXT: daddiu $sp, $sp, -16
+; SHRINK-WRAP-64-STATIC-NEXT: .cfi_def_cfa_offset 16
+; SHRINK-WRAP-64-STATIC-NEXT: sd $ra, 8($sp) # 8-byte Folded Spill
+; SHRINK-WRAP-64-STATIC-NEXT: .cfi_offset 31, -8
+; SHRINK-WRAP-64-STATIC-NEXT: sll $4, $4, 0
+; SHRINK-WRAP-64-STATIC-NEXT: #APP
+;
+; NO-SHRINK-WRAP-64-STATIC-LABEL: foo2:
+; NO-SHRINK-WRAP-64-STATIC: # %bb.0:
+; NO-SHRINK-WRAP-64-STATIC-NEXT: daddiu $sp, $sp, -16
+; NO-SHRINK-WRAP-64-STATIC-NEXT: .cfi_def_cfa_offset 16
+; NO-SHRINK-WRAP-64-STATIC-NEXT: sd $ra, 8($sp) # 8-byte Folded Spill
+; NO-SHRINK-WRAP-64-STATIC-NEXT: .cfi_offset 31, -8
+; NO-SHRINK-WRAP-64-STATIC-NEXT: addiu $1, $zero, 4
+; NO-SHRINK-WRAP-64-STATIC-NEXT: bne $4, $1, .LBB1_2
+; NO-SHRINK-WRAP-64-STATIC-NEXT: nop
+; NO-SHRINK-WRAP-64-STATIC-NEXT: # %bb.1:
+; NO-SHRINK-WRAP-64-STATIC-NEXT: j .LBB1_3
+; NO-SHRINK-WRAP-64-STATIC-NEXT: nop
+; NO-SHRINK-WRAP-64-STATIC-NEXT: .LBB1_2: # %if.then
+; NO-SHRINK-WRAP-64-STATIC-NEXT: sll $4, $4, 0
+; NO-SHRINK-WRAP-64-STATIC-NEXT: #APP
+;
+; SHRINK-WRAP-64-PIC-LABEL: foo2:
+; SHRINK-WRAP-64-PIC: # %bb.0:
+; SHRINK-WRAP-64-PIC-NEXT: lui $1, %hi(%neg(%gp_rel(foo2)))
+; SHRINK-WRAP-64-PIC-NEXT: daddu $2, $1, $25
+; SHRINK-WRAP-64-PIC-NEXT: addiu $1, $zero, 4
+; SHRINK-WRAP-64-PIC-NEXT: bne $4, $1, .LBB1_3
+; SHRINK-WRAP-64-PIC-NEXT: nop
+; SHRINK-WRAP-64-PIC-NEXT: # %bb.1:
+; SHRINK-WRAP-64-PIC-NEXT: daddiu $sp, $sp, -16
+; SHRINK-WRAP-64-PIC-NEXT: sd $ra, 0($sp)
+; SHRINK-WRAP-64-PIC-NEXT: daddiu $1, $zero, %hi(.LBB1_4-.LBB1_2)
+; SHRINK-WRAP-64-PIC-NEXT: dsll $1, $1, 16
+; SHRINK-WRAP-64-PIC-NEXT: bal .LBB1_2
+; SHRINK-WRAP-64-PIC-NEXT: daddiu $1, $1, %lo(.LBB1_4-.LBB1_2)
+; SHRINK-WRAP-64-PIC-NEXT: .LBB1_2:
+; SHRINK-WRAP-64-PIC-NEXT: daddu $1, $ra, $1
+; SHRINK-WRAP-64-PIC-NEXT: ld $ra, 0($sp)
+; SHRINK-WRAP-64-PIC-NEXT: jr $1
+; SHRINK-WRAP-64-PIC-NEXT: daddiu $sp, $sp, 16
+; SHRINK-WRAP-64-PIC-NEXT: .LBB1_3: # %if.then
+; SHRINK-WRAP-64-PIC-NEXT: daddiu $sp, $sp, -16
+; SHRINK-WRAP-64-PIC-NEXT: .cfi_def_cfa_offset 16
+; SHRINK-WRAP-64-PIC-NEXT: sd $ra, 8($sp) # 8-byte Folded Spill
+; SHRINK-WRAP-64-PIC-NEXT: sd $gp, 0($sp) # 8-byte Folded Spill
+; SHRINK-WRAP-64-PIC-NEXT: .cfi_offset 31, -8
+; SHRINK-WRAP-64-PIC-NEXT: .cfi_offset 28, -16
+; SHRINK-WRAP-64-PIC-NEXT: daddiu $gp, $2, %lo(%neg(%gp_rel(foo2)))
+; SHRINK-WRAP-64-PIC-NEXT: sll $4, $4, 0
+; SHRINK-WRAP-64-PIC-NEXT: #APP
+;
+; NO-SHRINK-WRAP-64-PIC-LABEL: foo2:
+; NO-SHRINK-WRAP-64-PIC: # %bb.0:
+; NO-SHRINK-WRAP-64-PIC-NEXT: daddiu $sp, $sp, -16
+; NO-SHRINK-WRAP-64-PIC-NEXT: .cfi_def_cfa_offset 16
+; NO-SHRINK-WRAP-64-PIC-NEXT: sd $ra, 8($sp) # 8-byte Folded Spill
+; NO-SHRINK-WRAP-64-PIC-NEXT: sd $gp, 0($sp) # 8-byte Folded Spill
+; NO-SHRINK-WRAP-64-PIC-NEXT: .cfi_offset 31, -8
+; NO-SHRINK-WRAP-64-PIC-NEXT: .cfi_offset 28, -16
+; NO-SHRINK-WRAP-64-PIC-NEXT: lui $1, %hi(%neg(%gp_rel(foo2)))
+; NO-SHRINK-WRAP-64-PIC-NEXT: daddu $2, $1, $25
+; NO-SHRINK-WRAP-64-PIC-NEXT: addiu $1, $zero, 4
+; NO-SHRINK-WRAP-64-PIC-NEXT: bne $4, $1, .LBB1_3
+; NO-SHRINK-WRAP-64-PIC-NEXT: nop
+; NO-SHRINK-WRAP-64-PIC-NEXT: # %bb.1:
+; NO-SHRINK-WRAP-64-PIC-NEXT: daddiu $sp, $sp, -16
+; NO-SHRINK-WRAP-64-PIC-NEXT: sd $ra, 0($sp)
+; NO-SHRINK-WRAP-64-PIC-NEXT: daddiu $1, $zero, %hi(.LBB1_4-.LBB1_2)
+; NO-SHRINK-WRAP-64-PIC-NEXT: dsll $1, $1, 16
+; NO-SHRINK-WRAP-64-PIC-NEXT: bal .LBB1_2
+; NO-SHRINK-WRAP-64-PIC-NEXT: daddiu $1, $1, %lo(.LBB1_4-.LBB1_2)
+; NO-SHRINK-WRAP-64-PIC-NEXT: .LBB1_2:
+; NO-SHRINK-WRAP-64-PIC-NEXT: daddu $1, $ra, $1
+; NO-SHRINK-WRAP-64-PIC-NEXT: ld $ra, 0($sp)
+; NO-SHRINK-WRAP-64-PIC-NEXT: jr $1
+; NO-SHRINK-WRAP-64-PIC-NEXT: daddiu $sp, $sp, 16
+; NO-SHRINK-WRAP-64-PIC-NEXT: .LBB1_3: # %if.then
+; NO-SHRINK-WRAP-64-PIC-NEXT: daddiu $gp, $2, %lo(%neg(%gp_rel(foo2)))
+; NO-SHRINK-WRAP-64-PIC-NEXT: sll $4, $4, 0
+; NO-SHRINK-WRAP-64-PIC-NEXT: #APP
+ %1 = icmp ne i32 %a, 4
+ br i1 %1, label %if.then, label %if.end
+
+if.then:
+ call void asm sideeffect ".space 1048576", "~{$1}"()
+ call void @f(i32 signext %a)
+ br label %if.end
+
+if.end:
+ ret i32 0
+}
More information about the llvm-commits
mailing list