[llvm-commits] [llvm] r157164 - /llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp

Jakob Stoklund Olesen stoklund at 2pi.dk
Sun May 20 11:42:55 PDT 2012


Author: stoklund
Date: Sun May 20 13:42:55 2012
New Revision: 157164

URL: http://llvm.org/viewvc/llvm-project?rev=157164&view=rev
Log:
Constrain regclasses in PeepholeOptimizer.

It can be necessary to restrict to a sub-class before accessing
sub-registers.

Modified:
    llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp

Modified: llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp?rev=157164&r1=157163&r2=157164&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp (original)
+++ llvm/trunk/lib/CodeGen/PeepholeOptimizer.cpp Sun May 20 13:42:55 2012
@@ -150,6 +150,13 @@
     // No other uses.
     return false;
 
+  // Ensure DstReg can get a register class that actually supports
+  // sub-registers. Don't change the class until we commit.
+  const TargetRegisterClass *DstRC = MRI->getRegClass(DstReg);
+  DstRC = TM->getRegisterInfo()->getSubClassWithSubReg(DstRC, SubIdx);
+  if (!DstRC)
+    return false;
+
   // The source has other uses. See if we can replace the other uses with use of
   // the result of the extension.
   SmallPtrSet<MachineBasicBlock*, 4> ReachedBBs;
@@ -247,8 +254,10 @@
         continue;
 
       // About to add uses of DstReg, clear DstReg's kill flags.
-      if (!Changed)
+      if (!Changed) {
         MRI->clearKillFlags(DstReg);
+        MRI->constrainRegClass(DstReg, DstRC);
+      }
 
       unsigned NewVR = MRI->createVirtualRegister(RC);
       BuildMI(*UseMBB, UseMI, UseMI->getDebugLoc(),





More information about the llvm-commits mailing list