Index: include/llvm/Analysis/TargetTransformInfoImpl.h =================================================================== --- include/llvm/Analysis/TargetTransformInfoImpl.h +++ include/llvm/Analysis/TargetTransformInfoImpl.h @@ -807,15 +807,9 @@ return static_cast(this)->getCallCost(F, Arguments); } - if (const CastInst *CI = dyn_cast(U)) { - // Result of a cmp instruction is often extended (to be used by other - // cmp instructions, logical or return instructions). These are usually - // nop on most sane targets. - if (isa(CI->getOperand(0))) - return TTI::TCC_Free; - if (isa(CI) || isa(CI) || isa(CI)) - return static_cast(this)->getExtCost(CI, Operands.back()); - } + if (isa(U) || isa(U) || isa(U)) + return static_cast(this)->getExtCost(cast(U), + Operands.back()); return static_cast(this)->getOperationCost( Operator::getOpcode(U), U->getType(), Index: test/Transforms/Inline/SystemZ/ext-i1-cost.ll =================================================================== --- /dev/null +++ test/Transforms/Inline/SystemZ/ext-i1-cost.ll @@ -0,0 +1,60 @@ +; REQUIRES: asserts +; RUN: opt -inline -mtriple=s390x-unknown-linux -mcpu=z13 -S \ +; RUN: -debug-only=inline-cost < %s 2>&1 | FileCheck %s +; +; Check that getUserCost() does not return TCC_Free for extensions of +; i1. This is tested indirectly by looking at the NumInstructionsSimplified +; stat from Inliner. Only cost-free instructions increase this counter so the +; functions below should get a value of 1 for it (for the ret instruction). + +define i64 @outer1(i64 %v) { + %z = call i64 @inner1(i64 %v) + ret i64 %z +} +; CHECK: Analyzing call of inner1... (caller:outer1) +; CHECK: NumInstructionsSimplified: 1 +; CHECK: NumInstructions: 3 +define i64 @inner1(i64 %v) { + %cmp = icmp eq i64 %v, 0 + %z = zext i1 %cmp to i64 + ret i64 %z +} + +define i64 @outer2(i64 %v) { + %z = call i64 @inner2(i64 %v) + ret i64 %z +} +; CHECK: Analyzing call of inner2... (caller:outer2) +; CHECK: NumInstructionsSimplified: 1 +; CHECK: NumInstructions: 3 +define i64 @inner2(i64 %v) { + %cmp = icmp eq i64 %v, 0 + %z = sext i1 %cmp to i64 + ret i64 %z +} + +define double @outer3(i64 %v) { + %z = call double @inner3(i64 %v) + ret double %z +} +; CHECK: Analyzing call of inner3... (caller:outer3) +; CHECK: NumInstructionsSimplified: 1 +; CHECK: NumInstructions: 3 +define double @inner3(i64 %v) { + %cmp = icmp eq i64 %v, 0 + %z = uitofp i1 %cmp to double + ret double %z +} + +define double @outer4(i64 %v) { + %z = call double @inner4(i64 %v) + ret double %z +} +; CHECK: Analyzing call of inner4... (caller:outer4) +; CHECK: NumInstructionsSimplified: 1 +; CHECK: NumInstructions: 3 +define double @inner4(i64 %v) { + %cmp = icmp eq i64 %v, 0 + %z = sitofp i1 %cmp to double + ret double %z +}