[llvm] r345818 - [SystemZ::TTI] Recognize the higher cost of scalar i1 -> fp conversion

Jonas Paulsson via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 1 02:05:32 PDT 2018


Author: jonpa
Date: Thu Nov  1 02:05:32 2018
New Revision: 345818

URL: http://llvm.org/viewvc/llvm-project?rev=345818&view=rev
Log:
[SystemZ::TTI]  Recognize the higher cost of scalar i1 -> fp conversion

Scalar i1 to fp conversions are done with a branch sequence, so it should
have a higher cost.

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

Added:
    llvm/trunk/test/Analysis/CostModel/SystemZ/cmp-tofp-scalar.ll
Modified:
    llvm/trunk/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp

Modified: llvm/trunk/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp?rev=345818&r1=345817&r2=345818&view=diff
==============================================================================
--- llvm/trunk/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp (original)
+++ llvm/trunk/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp Thu Nov  1 02:05:32 2018
@@ -749,7 +749,9 @@ int SystemZTTIImpl::getCastInstrCost(uns
     assert (!Dst->isVectorTy());
 
     if (Opcode == Instruction::SIToFP || Opcode == Instruction::UIToFP)
-      return (SrcScalarBits >= 32 ? 1 : 2 /*i8/i16 extend*/);
+      return (SrcScalarBits >= 32
+                ? 1
+                : SrcScalarBits > 1 ? 2 /*i8/i16 extend*/ : 5 /*branch seq.*/);
 
     if ((Opcode == Instruction::ZExt || Opcode == Instruction::SExt) &&
         Src->isIntegerTy(1)) {

Added: llvm/trunk/test/Analysis/CostModel/SystemZ/cmp-tofp-scalar.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/SystemZ/cmp-tofp-scalar.ll?rev=345818&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/CostModel/SystemZ/cmp-tofp-scalar.ll (added)
+++ llvm/trunk/test/Analysis/CostModel/SystemZ/cmp-tofp-scalar.ll Thu Nov  1 02:05:32 2018
@@ -0,0 +1,23 @@
+; RUN: opt < %s -cost-model -analyze -mtriple=systemz-unknown -mcpu=z13 | FileCheck %s
+;
+; Costs for conversion of i1 to fp.
+
+define float @fun0(i64 %val1, i64 %val2) {
+  %cmp = icmp eq i64 %val1, %val2
+  %v = uitofp i1 %cmp to float
+  ret float %v
+
+; CHECK: fun0
+; CHECK: cost of 1 for instruction:   %cmp = icmp eq i64 %val1, %val2
+; CHECK: cost of 5 for instruction:   %v = uitofp i1 %cmp to float
+}
+
+define double @fun1(i64 %val1, i64 %val2) {
+  %cmp = icmp eq i64 %val1, %val2
+  %v = uitofp i1 %cmp to double
+  ret double %v
+
+; CHECK: fun1
+; CHECK: cost of 1 for instruction:   %cmp = icmp eq i64 %val1, %val2
+; CHECK: cost of 5 for instruction:   %v = uitofp i1 %cmp to double
+}




More information about the llvm-commits mailing list