OSDN Git Service

[CodeGenPrepare] Fix the check of the legality of an instruction.
[android-x86/external-llvm.git] / lib / CodeGen / CodeGenPrepare.cpp
index e81a909..0c765b6 100644 (file)
@@ -1756,7 +1756,12 @@ AddressingModeMatcher::IsPromotionProfitable(unsigned MatchedSize,
   Instruction *PromotedInst = dyn_cast<Instruction>(PromotedOperand);
   if (!PromotedInst)
     return false;
-  return TLI.isOperationLegalOrCustom(PromotedInst->getOpcode(),
+  int ISDOpcode = TLI.InstructionOpcodeToISD(PromotedInst->getOpcode());
+  // If the ISDOpcode is undefined, it was undefined before the promotion.
+  if (!ISDOpcode)
+    return true;
+  // Otherwise, check if the promoted instruction is legal or not.
+  return TLI.isOperationLegalOrCustom(ISDOpcode,
                                       EVT::getEVT(PromotedInst->getType()));
 }