I have finally seen the light. The code to change the opcode must live higher in
authorMisha Brukman <brukman+llvm@gmail.com>
Wed, 4 Jun 2003 04:54:06 +0000 (04:54 +0000)
committerMisha Brukman <brukman+llvm@gmail.com>
Wed, 4 Jun 2003 04:54:06 +0000 (04:54 +0000)
the loop, and in both cases. In the first case, it is a VReg that is a constant
so it may be actually converted to a constant. In the second case, it is already
a constant, but then if it doesn't change its type (e.g. to become a register
and have the value loaded from memory if it is too large to live in its
instruction field), we must change the opcode BEFORE the 'continue', otherwise
we miss the opportunity.

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

lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp
lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp

index f654e90100bb8742960779c610eb353948d61408..86a7e7042cd77acee8f782232d21473291820b08 100644 (file)
@@ -186,6 +186,12 @@ FixConstantOperandsForInstr(Instruction* vmInstr,
                                       immedValue);
             if (opType == MachineOperand::MO_VirtualRegister)
               constantThatMustBeLoaded = true;
+            else {
+              // The optype has changed from being a register to an immediate
+              // This means we need to change the opcode, e.g. ADDr -> ADDi
+              unsigned newOpcode = convertOpcodeFromRegToImm(opCode);
+              minstr->setOpcode(newOpcode);
+            }
           }
         }
       else
@@ -203,6 +209,13 @@ FixConstantOperandsForInstr(Instruction* vmInstr,
                                     opCode, target, (immedPos == (int)op), 
                                     machineRegNum, immedValue);
 
+          if (opType == MachineOperand::MO_SignExtendedImmed) {
+            // The optype is an immediate value
+            // This means we need to change the opcode, e.g. ADDr -> ADDi
+            unsigned newOpcode = convertOpcodeFromRegToImm(opCode);
+            minstr->setOpcode(newOpcode);
+          }
+
           if (opType == mop.getType()) 
             continue;           // no change: this is the most common case
 
@@ -220,10 +233,6 @@ FixConstantOperandsForInstr(Instruction* vmInstr,
       else if (opType == MachineOperand::MO_SignExtendedImmed ||
                opType == MachineOperand::MO_UnextendedImmed) {
         minstr->SetMachineOperandConst(op, opType, immedValue);
-        // The optype has changed from being a register to an immediate
-        // This means we need to change the opcode, e.g. ADDr -> ADDi
-        unsigned newOpcode = convertOpcodeFromRegToImm(opCode);
-        minstr->setOpcode(newOpcode);
       } else if (constantThatMustBeLoaded ||
                (opValue && isa<GlobalValue>(opValue)))
         { // opValue is a constant that must be explicitly loaded into a reg
index f654e90100bb8742960779c610eb353948d61408..86a7e7042cd77acee8f782232d21473291820b08 100644 (file)
@@ -186,6 +186,12 @@ FixConstantOperandsForInstr(Instruction* vmInstr,
                                       immedValue);
             if (opType == MachineOperand::MO_VirtualRegister)
               constantThatMustBeLoaded = true;
+            else {
+              // The optype has changed from being a register to an immediate
+              // This means we need to change the opcode, e.g. ADDr -> ADDi
+              unsigned newOpcode = convertOpcodeFromRegToImm(opCode);
+              minstr->setOpcode(newOpcode);
+            }
           }
         }
       else
@@ -203,6 +209,13 @@ FixConstantOperandsForInstr(Instruction* vmInstr,
                                     opCode, target, (immedPos == (int)op), 
                                     machineRegNum, immedValue);
 
+          if (opType == MachineOperand::MO_SignExtendedImmed) {
+            // The optype is an immediate value
+            // This means we need to change the opcode, e.g. ADDr -> ADDi
+            unsigned newOpcode = convertOpcodeFromRegToImm(opCode);
+            minstr->setOpcode(newOpcode);
+          }
+
           if (opType == mop.getType()) 
             continue;           // no change: this is the most common case
 
@@ -220,10 +233,6 @@ FixConstantOperandsForInstr(Instruction* vmInstr,
       else if (opType == MachineOperand::MO_SignExtendedImmed ||
                opType == MachineOperand::MO_UnextendedImmed) {
         minstr->SetMachineOperandConst(op, opType, immedValue);
-        // The optype has changed from being a register to an immediate
-        // This means we need to change the opcode, e.g. ADDr -> ADDi
-        unsigned newOpcode = convertOpcodeFromRegToImm(opCode);
-        minstr->setOpcode(newOpcode);
       } else if (constantThatMustBeLoaded ||
                (opValue && isa<GlobalValue>(opValue)))
         { // opValue is a constant that must be explicitly loaded into a reg