summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNadav Rotem <nrotem@apple.com>2012-11-02 22:31:56 +0000
committerNadav Rotem <nrotem@apple.com>2012-11-02 22:31:56 +0000
commitf1495671605b50a4b0386697fee0b76ebae9d17f (patch)
treebde0209eb4040e18f115562308ccc14b695ef552
parent4c8edb41e5b9697d9a6bfa5761dbba9430626365 (diff)
downloadllvm-f1495671605b50a4b0386697fee0b76ebae9d17f.tar.gz
llvm-f1495671605b50a4b0386697fee0b76ebae9d17f.tar.bz2
llvm-f1495671605b50a4b0386697fee0b76ebae9d17f.tar.xz
CostModel: add support for Vector Insert and Extract.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167329 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/TargetTransformInfo.h3
-rw-r--r--lib/Analysis/CostModel.cpp18
-rw-r--r--test/Analysis/CostModel/X86/loop_v2.ll43
3 files changed, 63 insertions, 1 deletions
diff --git a/include/llvm/TargetTransformInfo.h b/include/llvm/TargetTransformInfo.h
index c65ef17dfa..94db490443 100644
--- a/include/llvm/TargetTransformInfo.h
+++ b/include/llvm/TargetTransformInfo.h
@@ -179,8 +179,9 @@ public:
}
/// Returns the expected cost of vector Insert and Extract.
+ /// Use -1 to indicate that there is no information on the index value.
virtual unsigned getVectorInstrCost(unsigned Opcode, Type *Val,
- unsigned Index = 0) const {
+ unsigned Index = -1) const {
return 1;
}
diff --git a/lib/Analysis/CostModel.cpp b/lib/Analysis/CostModel.cpp
index 142d287384..5adbf45810 100644
--- a/lib/Analysis/CostModel.cpp
+++ b/lib/Analysis/CostModel.cpp
@@ -150,6 +150,24 @@ unsigned CostModelAnalysis::getInstructionCost(Instruction *I) const {
Type *SrcTy = I->getOperand(0)->getType();
return VTTI->getCastInstrCost(I->getOpcode(), I->getType(), SrcTy);
}
+ case Instruction::ExtractElement: {
+ ExtractElementInst * EEI = cast<ExtractElementInst>(I);
+ ConstantInt *CI = dyn_cast<ConstantInt>(I->getOperand(1));
+ unsigned Idx = -1;
+ if (CI)
+ Idx = CI->getZExtValue();
+ return VTTI->getVectorInstrCost(I->getOpcode(),
+ EEI->getOperand(0)->getType(), Idx);
+ }
+ case Instruction::InsertElement: {
+ InsertElementInst * IE = cast<InsertElementInst>(I);
+ ConstantInt *CI = dyn_cast<ConstantInt>(IE->getOperand(2));
+ unsigned Idx = -1;
+ if (CI)
+ Idx = CI->getZExtValue();
+ return VTTI->getVectorInstrCost(I->getOpcode(),
+ IE->getType(), Idx);
+ }
default:
// We don't have any information on this instruction.
return -1;
diff --git a/test/Analysis/CostModel/X86/loop_v2.ll b/test/Analysis/CostModel/X86/loop_v2.ll
new file mode 100644
index 0000000000..260a60676a
--- /dev/null
+++ b/test/Analysis/CostModel/X86/loop_v2.ll
@@ -0,0 +1,43 @@
+; RUN: opt < %s -cost-model -analyze -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-apple-macosx10.9.0"
+
+define i32 @foo(i32* nocapture %A) nounwind uwtable readonly ssp {
+vector.ph:
+ br label %vector.body
+
+vector.body: ; preds = %vector.body, %vector.ph
+ %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
+ %vec.phi = phi <2 x i32> [ zeroinitializer, %vector.ph ], [ %12, %vector.body ]
+ %0 = getelementptr inbounds i32* %A, i64 %index
+ %1 = bitcast i32* %0 to <2 x i32>*
+ %2 = load <2 x i32>* %1, align 4
+ %3 = sext <2 x i32> %2 to <2 x i64>
+ ;CHECK: cost of 1 {{.*}} extract
+ %4 = extractelement <2 x i64> %3, i32 0
+ %5 = getelementptr inbounds i32* %A, i64 %4
+ ;CHECK: cost of 1 {{.*}} extract
+ %6 = extractelement <2 x i64> %3, i32 1
+ %7 = getelementptr inbounds i32* %A, i64 %6
+ %8 = load i32* %5, align 4, !tbaa !0
+ ;CHECK: cost of 1 {{.*}} insert
+ %9 = insertelement <2 x i32> undef, i32 %8, i32 0
+ %10 = load i32* %7, align 4, !tbaa !0
+ ;CHECK: cost of 1 {{.*}} insert
+ %11 = insertelement <2 x i32> %9, i32 %10, i32 1
+ %12 = add nsw <2 x i32> %11, %vec.phi
+ %index.next = add i64 %index, 2
+ %13 = icmp eq i64 %index.next, 192
+ br i1 %13, label %for.end, label %vector.body
+
+for.end: ; preds = %vector.body
+ %14 = extractelement <2 x i32> %12, i32 0
+ %15 = extractelement <2 x i32> %12, i32 1
+ %16 = add i32 %14, %15
+ ret i32 %16
+}
+
+!0 = metadata !{metadata !"int", metadata !1}
+!1 = metadata !{metadata !"omnipotent char", metadata !2}
+!2 = metadata !{metadata !"Simple C/C++ TBAA"}