aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Paulsson <paulsson@linux.vnet.ibm.com>2018-11-02 17:53:31 +0000
committerJonas Paulsson <paulsson@linux.vnet.ibm.com>2018-11-02 17:53:31 +0000
commitcced2a2775e1d00dd8cb36e3c6b5acd6accc4c08 (patch)
treef2d68e48b2d2f2b77ead41b734c10ce48674d2f0
parentb6355cc56158557f8173136e6a30b8ee21e7d7de (diff)
downloadllvm-cced2a2775e1d00dd8cb36e3c6b5acd6accc4c08.zip
llvm-cced2a2775e1d00dd8cb36e3c6b5acd6accc4c08.tar.gz
llvm-cced2a2775e1d00dd8cb36e3c6b5acd6accc4c08.tar.bz2
[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
-rw-r--r--llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp10
-rw-r--r--llvm/test/Analysis/CostModel/SystemZ/fp-cast.ll46
2 files changed, 52 insertions, 4 deletions
diff --git a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
index 279a8218..f296d80 100644
--- a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
@@ -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)) {
diff --git a/llvm/test/Analysis/CostModel/SystemZ/fp-cast.ll b/llvm/test/Analysis/CostModel/SystemZ/fp-cast.ll
index 4ea5a50..20feefb 100644
--- a/llvm/test/Analysis/CostModel/SystemZ/fp-cast.ll
+++ b/llvm/test/Analysis/CostModel/SystemZ/fp-cast.ll
@@ -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;
+}