Properly constrain register classes in 2-addr.
authorJakob Stoklund Olesen <stoklund@2pi.dk>
Sun, 20 May 2012 06:38:32 +0000 (06:38 +0000)
committerJakob Stoklund Olesen <stoklund@2pi.dk>
Sun, 20 May 2012 06:38:32 +0000 (06:38 +0000)
X86 has 2-addr instructions with different constraints on the tied def
and use operands. One is GR32, one is GR32_NOSP.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157149 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/TwoAddressInstructionPass.cpp
test/CodeGen/X86/shift-folding.ll

index 8164690e40abc082f2cfa3f6504d442a06df26aa..5218aa1f7a8be4ee802f6456dfdb259dfc061521 100644 (file)
@@ -1555,6 +1555,12 @@ bool TwoAddressInstructionPass::runOnMachineFunction(MachineFunction &MF) {
             MO.setIsKill(false);
             RemovedKillFlag = true;
           }
+
+          // Make sure regA is a legal regclass for the SrcIdx operand.
+          if (TargetRegisterInfo::isVirtualRegister(regA) &&
+              TargetRegisterInfo::isVirtualRegister(regB))
+            MRI->constrainRegClass(regA, MRI->getRegClass(regB));
+
           MO.setReg(regA);
 
           if (isCopy)
index 3ea601147bb091cbfe7ad80175554d0a7b7e47b8..c518cdd3aa4ea2037ab49acee357171c0e7ea617 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc < %s -march=x86 | FileCheck %s
+; RUN: llc < %s -march=x86 -verify-coalescing | FileCheck %s
 
 define i32* @test1(i32* %P, i32 %X) {
 ; CHECK: test1: