Index: lib/Target/SystemZ/SystemZTargetTransformInfo.cpp =================================================================== --- lib/Target/SystemZ/SystemZTargetTransformInfo.cpp +++ lib/Target/SystemZ/SystemZTargetTransformInfo.cpp @@ -767,10 +767,12 @@ else { // Scalar assert (!Dst->isVectorTy()); - if (Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP) - return (SrcScalarBits >= 32 - ? 1 - : SrcScalarBits > 1 ? 2 /*i8/i16 extend*/ : 5 /*branch seq.*/); + if (Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP) { + if (SrcScalarBits >= 32 || + (I != nullptr && isa(I->getOperand(0)))) + return 1; + return SrcScalarBits > 1 ? 2 /*i8/i16 extend*/ : 5 /*branch seq.*/; + } if ((Opcode == Instruction::ZExt || Opcode == Instruction::SExt) && Src->isIntegerTy(1)) { Index: test/Analysis/CostModel/SystemZ/fp-cast.ll =================================================================== --- test/Analysis/CostModel/SystemZ/fp-cast.ll +++ test/Analysis/CostModel/SystemZ/fp-cast.ll @@ -539,3 +539,49 @@ ret void; } + +define void @sitofp_extload(i16 *%src16, i8 *%src8) { + %ld16 = load i16, i16 *%src16 + %v6 = sitofp i16 %ld16 to fp128 + %v7 = sitofp i16 %ld16 to double + %v8 = sitofp i16 %ld16 to float + + %ld8 = load i8, i8 *%src8 + %v9 = sitofp i8 %ld8 to fp128 + %v10 = sitofp i8 %ld8 to double + %v11 = sitofp i8 %ld8 to float + +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %ld16 = load i16, i16* %src16 +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %v6 = sitofp i16 %ld16 to fp128 +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %v7 = sitofp i16 %ld16 to double +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %v8 = sitofp i16 %ld16 to float +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %ld8 = load i8, i8* %src8 +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %v9 = sitofp i8 %ld8 to fp128 +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %v10 = sitofp i8 %ld8 to double +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %v11 = sitofp i8 %ld8 to float + + ret void; +} + +define void @uitofp_extload(i16 *%src16, i8 *%src8) { + %ld16 = load i16, i16 *%src16 + %v6 = uitofp i16 %ld16 to fp128 + %v7 = uitofp i16 %ld16 to double + %v8 = uitofp i16 %ld16 to float + + %ld8 = load i8, i8 *%src8 + %v9 = uitofp i8 %ld8 to fp128 + %v10 = uitofp i8 %ld8 to double + %v11 = uitofp i8 %ld8 to float + +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %ld16 = load i16, i16* %src16 +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %v6 = uitofp i16 %ld16 to fp128 +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %v7 = uitofp i16 %ld16 to double +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %v8 = uitofp i16 %ld16 to float +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %ld8 = load i8, i8* %src8 +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %v9 = uitofp i8 %ld8 to fp128 +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %v10 = uitofp i8 %ld8 to double +; CHECK: Cost Model: Found an estimated cost of 1 for instruction: %v11 = uitofp i8 %ld8 to float + + ret void; +}