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

Jonas Paulsson via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 2 10:53:31 PDT 2018


Author: jonpa
Date: Fri Nov  2 10:53:31 2018
New Revision: 346009

URL: http://llvm.org/viewvc/llvm-project?rev=346009&view=rev
Log:
[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

Modified:
    llvm/trunk/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
    llvm/trunk/test/Analysis/CostModel/SystemZ/fp-cast.ll

Modified: llvm/trunk/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp?rev=346009&r1=346008&r2=346009&view=diff
==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp Fri Nov  2 10:53:31 2018
@@ -748,10 +748,12 @@ int SystemZTTIImpl::getCastInstrCost(uns
   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)) {

Modified: llvm/trunk/test/Analysis/CostModel/SystemZ/fp-cast.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/SystemZ/fp-cast.ll?rev=346009&r1=346008&r2=346009&view=diff
==============================================================================
--- llvm/trunk/test/Analysis/CostModel/SystemZ/fp-cast.ll (original)
+++ llvm/trunk/test/Analysis/CostModel/SystemZ/fp-cast.ll Fri Nov  2 10:53:31 2018
@@ -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;
+}




More information about the llvm-commits mailing list