getCastInstrCost()

Jonas Paulsson via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 1 07:19:42 PST 2017


Hi,

It seems odd to think that a vector truncate could be a noop in 
getCastInstrCost().

Add a check so that this only applies to scalar types.

/Jonas


    unsigned getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src) {
      const TargetLoweringBase *TLI = getTLI();
      int ISD = TLI->InstructionOpcodeToISD(Opcode);
      assert(ISD && "Invalid opcode");
      std::pair<unsigned, MVT> SrcLT = TLI->getTypeLegalizationCost(DL, 
Src);
      std::pair<unsigned, MVT> DstLT = TLI->getTypeLegalizationCost(DL, 
Dst);

      // Check for NOOP conversions.
-    if (SrcLT.first == DstLT.first &&
+    if ((!Src->isVectorTy() && !Dst->isVectorTy()) &&
+        SrcLT.first == DstLT.first &&
          SrcLT.second.getSizeInBits() == DstLT.second.getSizeInBits()) {

        // Bitcast between types that are legalized to the same type are 
free.
       if (Opcode == Instruction::BitCast || Opcode == Instruction::Trunc)
          return 0;
      }



More information about the llvm-commits mailing list