[SystemZ::TTI] Improve cost handling of uint/sint to fp conversions.

Let i8/i16 uint/sint to fp conversions cost 1 if operand is a load.

Since the load already does the extension, there is no extra cost (previously
returned 2).

Review: Ulrich Weigand
https://reviews.llvm.org/D54028

llvm-svn: 346009
This commit is contained in:
Jonas Paulsson 2018-11-02 17:53:31 +00:00
parent b6355cc561
commit cced2a2775
2 changed files with 52 additions and 4 deletions

View File

@ -748,10 +748,12 @@ int SystemZTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst, Type *Src,
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<LoadInst>(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)) {

View File

@ -539,3 +539,49 @@ define void @uitofp() {
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;
}