[llvm-commits] CVS: llvm/lib/Target/ARM/ARMConstantIslandPass.cpp

Evan Cheng evan.cheng at apple.com
Wed Jan 31 10:19:23 PST 2007



Changes in directory llvm/lib/Target/ARM:

ARMConstantIslandPass.cpp updated: 1.14 -> 1.15
---
Log message:

ConstPool island bug: watch out for cases where UserMI is the last MI of the BB.

---
Diffs of the changes:  (+16 -4)

 ARMConstantIslandPass.cpp |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)


Index: llvm/lib/Target/ARM/ARMConstantIslandPass.cpp
diff -u llvm/lib/Target/ARM/ARMConstantIslandPass.cpp:1.14 llvm/lib/Target/ARM/ARMConstantIslandPass.cpp:1.15
--- llvm/lib/Target/ARM/ARMConstantIslandPass.cpp:1.14	Tue Jan 30 20:22:22 2007
+++ llvm/lib/Target/ARM/ARMConstantIslandPass.cpp	Wed Jan 31 12:19:07 2007
@@ -461,6 +461,7 @@
 /// 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 @@
     // 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 @@
   // 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);






More information about the llvm-commits mailing list