summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHal Finkel <hfinkel@anl.gov>2014-04-02 23:18:54 +0000
committerHal Finkel <hfinkel@anl.gov>2014-04-02 23:18:54 +0000
commit9263e6f08d26384d076e8e314ba0e72fe8ad3e2f (patch)
treeef97ef4805a72a289f3c0b2914e0eb87b06ca915
parenta18ad697a9e41d27fdf86d0c7b0c85758038d549 (diff)
downloadllvm-9263e6f08d26384d076e8e314ba0e72fe8ad3e2f.tar.gz
llvm-9263e6f08d26384d076e8e314ba0e72fe8ad3e2f.tar.bz2
llvm-9263e6f08d26384d076e8e314ba0e72fe8ad3e2f.tar.xz
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@205487 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/CodeGen/BasicTargetTransformInfo.cpp3
-rw-r--r--test/Analysis/CostModel/PowerPC/ext.ll21
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/CodeGen/BasicTargetTransformInfo.cpp b/lib/CodeGen/BasicTargetTransformInfo.cpp
index 03c5eba369..25486cf391 100644
--- a/lib/CodeGen/BasicTargetTransformInfo.cpp
+++ b/lib/CodeGen/BasicTargetTransformInfo.cpp
@@ -297,7 +297,8 @@ unsigned BasicTTI::getCastInstrCost(unsigned Opcode, Type *Dst,
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.
diff --git a/test/Analysis/CostModel/PowerPC/ext.ll b/test/Analysis/CostModel/PowerPC/ext.ll
new file mode 100644
index 0000000000..daaa8f5bac
--- /dev/null
+++ b/test/Analysis/CostModel/PowerPC/ext.ll
@@ -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
+}
+