Be over-conservative: scan for all used virtual registers and calculate maximal stack...
authorAnton Korobeynikov <asl@math.spbu.ru>
Wed, 23 Apr 2008 18:23:30 +0000 (18:23 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Wed, 23 Apr 2008 18:23:30 +0000 (18:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50167 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86RegisterInfo.cpp
lib/Target/X86/X86TargetMachine.cpp

index 2b14f6eb9b80735aab78b0c661830345944efd93..0d528f725832be17441a7503a76ee2f55958f68b 100644 (file)
@@ -1121,11 +1121,18 @@ namespace {
 
     virtual bool runOnMachineFunction(MachineFunction &MF) {
       MachineFrameInfo *FFI = MF.getFrameInfo();
+      MachineRegisterInfo &RI = MF.getRegInfo();
 
-      // Calculate and set max stack object alignment early, so we can decide
-      // whether we will need stack realignment (and thus FP).
+      // Calculate max stack alignment of all already allocated stack objects.
       unsigned MaxAlign = calculateMaxStackAlignment(FFI);
 
+      // Be over-conservative: scan over all vreg defs and find, whether vector
+      // registers are used. If yes - there is probability, that vector register
+      // will be spilled and thus stack needs to be aligned properly.
+      for (unsigned RegNum = TargetRegisterInfo::FirstVirtualRegister;
+           RegNum < RI.getLastVirtReg(); ++RegNum)
+        MaxAlign = std::max(MaxAlign, RI.getRegClass(RegNum)->getAlignment());
+
       FFI->setMaxAlignment(MaxAlign);
 
       return false;
index f75a77c6b0726298eeeec7afefc096b8215d51bf..218f356b9217e02cfaedc09151ca67021b4e85f5 100644 (file)
@@ -162,6 +162,8 @@ bool X86TargetMachine::addInstSelector(PassManagerBase &PM, bool Fast) {
 }
 
 bool X86TargetMachine::addPreRegAlloc(PassManagerBase &PM, bool Fast) {
+  // Calculate and set max stack object alignment early, so we can decide
+  // whether we will need stack realignment (and thus FP).
   PM.add(createX86MaxStackAlignmentCalculatorPass());
   return false;  // -print-machineinstr shouldn't print after this.
 }