[llvm] r205487 - Fix multi-register costs in BasicTTI::getCastInstrCost

Hal Finkel hfinkel at anl.gov
Wed Apr 2 16:18:55 PDT 2014


Author: hfinkel
Date: Wed Apr  2 18:18:54 2014
New Revision: 205487

URL: http://llvm.org/viewvc/llvm-project?rev=205487&view=rev
Log:
Fix multi-register costs in BasicTTI::getCastInstrCost

For an cast (extension, etc.), the currently logic predicts a low cost if the
associated operation (keyed on the destination type) is legal (or promoted).
This is not true when the number of values required to legalize the type is
changing. For example, <8 x i16> being sign extended by <8 x i32> is not
generically cheap on PPC with VSX, even though sign extension to v4i32 is
legal, because two output v4i32 values are required compared to the single
v8i16 input value, and without custom logic in the target, this conversion will
scalarize.

Added:
    llvm/trunk/test/Analysis/CostModel/PowerPC/ext.ll
Modified:
    llvm/trunk/lib/CodeGen/BasicTargetTransformInfo.cpp

Modified: llvm/trunk/lib/CodeGen/BasicTargetTransformInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/BasicTargetTransformInfo.cpp?rev=205487&r1=205486&r2=205487&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/BasicTargetTransformInfo.cpp (original)
+++ llvm/trunk/lib/CodeGen/BasicTargetTransformInfo.cpp Wed Apr  2 18:18:54 2014
@@ -297,7 +297,8 @@ unsigned BasicTTI::getCastInstrCost(unsi
     return 0;
 
   // If the cast is marked as legal (or promote) then assume low cost.
-  if (TLI->isOperationLegalOrPromote(ISD, DstLT.second))
+  if (SrcLT.first == DstLT.first &&
+      TLI->isOperationLegalOrPromote(ISD, DstLT.second))
     return 1;
 
   // Handle scalar conversions.

Added: llvm/trunk/test/Analysis/CostModel/PowerPC/ext.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/CostModel/PowerPC/ext.ll?rev=205487&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/CostModel/PowerPC/ext.ll (added)
+++ llvm/trunk/test/Analysis/CostModel/PowerPC/ext.ll Wed Apr  2 18:18:54 2014
@@ -0,0 +1,21 @@
+; RUN: opt < %s -cost-model -analyze -mtriple=powerpc64-unknown-linux-gnu -mcpu=pwr7 -mattr=+vsx | FileCheck %s
+target datalayout = "E-m:e-i64:64-n32:64"
+target triple = "powerpc64-unknown-linux-gnu"
+
+define void @exts() {
+
+  ; CHECK: cost of 1 {{.*}} sext
+  %v1 = sext i16 undef to i32
+
+  ; CHECK: cost of 1 {{.*}} sext
+  %v2 = sext <2 x i16> undef to <2 x i32>
+
+  ; CHECK: cost of 1 {{.*}} sext
+  %v3 = sext <4 x i16> undef to <4 x i32>
+
+  ; CHECK: cost of 216 {{.*}} sext
+  %v4 = sext <8 x i16> undef to <8 x i32>
+
+  ret void
+}
+





More information about the llvm-commits mailing list