summaryrefslogtreecommitdiff
path: root/lib/Target/ARM/ARMConstantIslandPass.cpp
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2007-01-31 18:19:07 +0000
committerEvan Cheng <evan.cheng@apple.com>2007-01-31 18:19:07 +0000
commit934536dab2585079d72b0218b3d5a2ea07795beb (patch)
tree8f21efcef920457570e6685aeb49cbac0f7b5025 /lib/Target/ARM/ARMConstantIslandPass.cpp
parenta88d6ca6f954bb45819a9ee02fc2a0e0a0ac1689 (diff)
downloadllvm-934536dab2585079d72b0218b3d5a2ea07795beb.tar.gz
llvm-934536dab2585079d72b0218b3d5a2ea07795beb.tar.bz2
llvm-934536dab2585079d72b0218b3d5a2ea07795beb.tar.xz
ConstPool island bug: watch out for cases where UserMI is the last MI of the BB.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33706 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/ARM/ARMConstantIslandPass.cpp')
-rw-r--r--lib/Target/ARM/ARMConstantIslandPass.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/Target/ARM/ARMConstantIslandPass.cpp b/lib/Target/ARM/ARMConstantIslandPass.cpp
index eca3b04fbb..32f8e8cb25 100644
--- a/lib/Target/ARM/ARMConstantIslandPass.cpp
+++ b/lib/Target/ARM/ARMConstantIslandPass.cpp
@@ -461,6 +461,7 @@ MachineBasicBlock *ARMConstantIslands::SplitBlockBeforeInstr(MachineInstr *MI) {
/// is out-of-range. If so, pick it up the constant pool value and move it some
/// place in-range.
bool ARMConstantIslands::HandleConstantPoolUser(MachineFunction &Fn, CPUser &U){
+ bool isThumb = AFI->isThumbFunction();
MachineInstr *UserMI = U.MI;
MachineInstr *CPEMI = U.CPEMI;
@@ -477,7 +478,7 @@ bool ARMConstantIslands::HandleConstantPoolUser(MachineFunction &Fn, CPUser &U){
// User before the CPE.
if (CPEOffset-UserOffset <= U.MaxDisp)
return false;
- } else if (!AFI->isThumbFunction()) {
+ } else if (!isThumb) {
// Thumb LDR cannot encode negative offset.
if (UserOffset-CPEOffset <= U.MaxDisp)
return false;
@@ -487,15 +488,26 @@ bool ARMConstantIslands::HandleConstantPoolUser(MachineFunction &Fn, CPUser &U){
// Solution guaranteed to work: split the user's MBB right after the user and
// insert a clone the CPE into the newly created water.
- MachineInstr *NextMI = next(MachineBasicBlock::iterator(UserMI));
+ MachineBasicBlock *UserMBB = UserMI->getParent();
+ MachineBasicBlock *NewMBB;
+
// TODO: Search for the best place to split the code. In practice, using
// loop nesting information to insert these guys outside of loops would be
// sufficient.
- MachineBasicBlock *NewBB = SplitBlockBeforeInstr(NextMI);
+ if (&UserMBB->back() == UserMI) {
+ assert(BBHasFallthrough(UserMBB) && "Expected a fallthrough BB!");
+ NewMBB = next(MachineFunction::iterator(UserMBB));
+ // Add an unconditional branch from UserMBB to fallthrough block.
+ BuildMI(UserMBB, TII->get(isThumb ? ARM::tB : ARM::B)).addMBB(NewMBB);
+ BBSizes[UserMBB->getNumber()] += isThumb ? 2 : 4;
+ } else {
+ MachineInstr *NextMI = next(MachineBasicBlock::iterator(UserMI));
+ NewMBB = SplitBlockBeforeInstr(NextMI);
+ }
// Okay, we know we can put an island before UserMBB now, do it!
MachineBasicBlock *NewIsland = new MachineBasicBlock();
- Fn.getBasicBlockList().insert(NewBB, NewIsland);
+ Fn.getBasicBlockList().insert(NewMBB, NewIsland);
// Update internal data structures to account for the newly inserted MBB.
UpdateForInsertedWaterBlock(NewIsland);