Index: llvm/include/llvm/Analysis/TargetTransformInfoImpl.h =================================================================== --- llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -846,14 +846,11 @@ case Instruction::IntToPtr: case Instruction::PtrToInt: case Instruction::Trunc: - if (getCastInstrCost(Opcode, Ty, OpTy, I) == TTI::TCC_Free || - TargetTTI->getCastInstrCost(Opcode, Ty, OpTy, I) == TTI::TCC_Free) - return TTI::TCC_Free; - break; case Instruction::BitCast: - if (getCastInstrCost(Opcode, Ty, OpTy, I) == TTI::TCC_Free) - return TTI::TCC_Free; - break; + // Check if the operation is free according to the datalayout. + if (getCastInstrCost(Opcode, Ty, OpTy, I) == 0) + return 0; + return TargetTTI->getCastInstrCost(Opcode, Ty, OpTy, I); case Instruction::FPExt: case Instruction::SExt: case Instruction::ZExt: Index: llvm/test/Analysis/CostModel/X86/size-cost.ll =================================================================== --- llvm/test/Analysis/CostModel/X86/size-cost.ll +++ llvm/test/Analysis/CostModel/X86/size-cost.ll @@ -30,7 +30,7 @@ define i64 @bitcast_f64_i64(double %x) { ; CHECK-LABEL: 'bitcast_f64_i64' -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %r = bitcast double %x to i64 +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %r = bitcast double %x to i64 ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %r ; %r = bitcast double %x to i64 @@ -39,7 +39,7 @@ define double @bitcast_i64_f64(i64 %x) { ; CHECK-LABEL: 'bitcast_i64_f64' -; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: %r = bitcast i64 %x to double +; CHECK-NEXT: Cost Model: Found an estimated cost of 0 for instruction: %r = bitcast i64 %x to double ; CHECK-NEXT: Cost Model: Found an estimated cost of 1 for instruction: ret double %r ; %r = bitcast i64 %x to double