Silly bug fix: Machine code vector could be empty for a no-op cast instruction,
authorVikram S. Adve <vadve@cs.uiuc.edu>
Mon, 9 Sep 2002 14:54:21 +0000 (14:54 +0000)
committerVikram S. Adve <vadve@cs.uiuc.edu>
Mon, 9 Sep 2002 14:54:21 +0000 (14:54 +0000)
e.g., cast double to double.

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

lib/Target/SparcV9/SparcV9InstrSelection.cpp

index 368afbb4ec9725ae23bfaa0f3b5ca68b2f602304..6c5caaf6bfff3c68c8fdd429a92dab7ccf8e8318 100644 (file)
@@ -1555,19 +1555,23 @@ GetInstructionsByRule(InstructionNode* subtreeRoot,
       case  31:        // reg:   ToFloatTy(reg):
       case  32:        // reg:   ToDoubleTy(reg):
       case 232:        // reg:   ToDoubleTy(Constant):
-
+      
         // If this instruction has a parent (a user) in the tree 
         // and the user is translated as an FsMULd instruction,
         // then the cast is unnecessary.  So check that first.
         // In the future, we'll want to do the same for the FdMULq instruction,
         // so do the check here instead of only for ToFloatTy(reg).
         // 
-        if (subtreeRoot->parent() != NULL &&
-            MachineCodeForInstruction::get(((InstructionNode*)subtreeRoot->parent())->getInstruction())[0]->getOpCode() == FSMULD)
+        if (subtreeRoot->parent() != NULL)
           {
-            forwardOperandNum = 0;          // forward first operand to user
+            const MachineCodeForInstruction& mcfi =
+              MachineCodeForInstruction::get(
+                cast<InstructionNode>(subtreeRoot->parent())->getInstruction());
+            if (mcfi.size() == 0 || mcfi.front()->getOpCode() == FSMULD)
+              forwardOperandNum = 0;    // forward first operand to user
           }
-        else
+
+        if (forwardOperandNum != 0)     // we do need the cast
           {
             Value* leftVal = subtreeRoot->leftChild()->getValue();
             const Type* opType = leftVal->getType();