Index: llvm/include/llvm/Analysis/TargetTransformInfoImpl.h =================================================================== --- llvm/include/llvm/Analysis/TargetTransformInfoImpl.h +++ llvm/include/llvm/Analysis/TargetTransformInfoImpl.h @@ -854,9 +854,9 @@ case Instruction::FPExt: case Instruction::SExt: case Instruction::ZExt: - if (TargetTTI->getExtCost(I, Operands.back()) == TTI::TCC_Free) - return TTI::TCC_Free; - break; + if (I && TargetTTI->getExtCost(I, Operands.back()) == 0) + return 0; + return TargetTTI->getCastInstrCost(Opcode, Ty, OpTy, I); } // By default, just classify everything as 'basic'. return TTI::TCC_Basic; Index: llvm/test/Analysis/CostModel/SystemZ/ext-of-icmp-cost.ll =================================================================== --- llvm/test/Analysis/CostModel/SystemZ/ext-of-icmp-cost.ll +++ llvm/test/Analysis/CostModel/SystemZ/ext-of-icmp-cost.ll @@ -7,7 +7,7 @@ define i64 @fun1(i64 %v) { ; CHECK-LABEL: 'fun1' ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %cmp = icmp eq i64 %v, 0 -; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %z = zext i1 %cmp to i64 +; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %z = zext i1 %cmp to i64 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %z %cmp = icmp eq i64 %v, 0 %z = zext i1 %cmp to i64 @@ -17,7 +17,7 @@ define i64 @fun2(i64 %v) { ; CHECK-LABEL: 'fun2' ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %cmp = icmp eq i64 %v, 0 -; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %z = sext i1 %cmp to i64 +; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %z = sext i1 %cmp to i64 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %z %cmp = icmp eq i64 %v, 0 %z = sext i1 %cmp to i64 @@ -46,7 +46,7 @@ define i64 @fun5(i1 %v) { ; CHECK-LABEL: 'fun5' -; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %z = zext i1 %v to i64 +; CHECK: Cost Model: Found an estimated cost of 2 for instruction: %z = zext i1 %v to i64 ; CHECK: Cost Model: Found an estimated cost of 1 for instruction: ret i64 %z %z = zext i1 %v to i64 ret i64 %z