From 8def8d9263264cc0e8fc0be5438c4df19c963f47 Mon Sep 17 00:00:00 2001 From: Hal Finkel Date: Tue, 16 Sep 2014 04:35:50 +0000 Subject: [PATCH] Fix BasicTTI::getCmpSelInstrCost to deal with illegal vector types The default implementation of getCmpSelInstrCost, which provides the cost of icmp/fcmp/select instructions, did not deal sensibly with illegal vector types that were scalarized. We'd ask for the legalization cost of the vector type, which would return something like (4, f64) given an input of <4 x double>, and we'd then check the TLI status of the ISD opcode on that scalar type. This would result in querying (ISD::VSELECT, f64), for example. Amusingly enough, ISD::VSELECT on scalar types is marked as Legal by default (as with most other operations), and most backends never change this because VSELECT is never generated on scalars. However, seeing the resulting operation as Legal, we'd neglect to add the scalarization cost before returning. The result is that we'd grossly under-estimate the cost of cmps/selects on illegal vector types. Now, if type legalization clearly results in scalarization, we skip the early return and add the scalarization cost. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217859 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/BasicTargetTransformInfo.cpp | 3 ++- test/Analysis/CostModel/PowerPC/cmp-expanded.ll | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/Analysis/CostModel/PowerPC/cmp-expanded.ll diff --git a/lib/CodeGen/BasicTargetTransformInfo.cpp b/lib/CodeGen/BasicTargetTransformInfo.cpp index 3e0e09e658e..e79f458efbf 100644 --- a/lib/CodeGen/BasicTargetTransformInfo.cpp +++ b/lib/CodeGen/BasicTargetTransformInfo.cpp @@ -468,7 +468,8 @@ unsigned BasicTTI::getCmpSelInstrCost(unsigned Opcode, Type *ValTy, std::pair LT = TLI->getTypeLegalizationCost(ValTy); - if (!TLI->isOperationExpand(ISD, LT.second)) { + if (!(ValTy->isVectorTy() && !LT.second.isVector()) && + !TLI->isOperationExpand(ISD, LT.second)) { // The operation is legal. Assume it costs 1. Multiply // by the type-legalization overhead. return LT.first * 1; diff --git a/test/Analysis/CostModel/PowerPC/cmp-expanded.ll b/test/Analysis/CostModel/PowerPC/cmp-expanded.ll new file mode 100644 index 00000000000..38c8439b9fb --- /dev/null +++ b/test/Analysis/CostModel/PowerPC/cmp-expanded.ll @@ -0,0 +1,14 @@ +; 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() { + + ; VSX is disabled, so this cost needs to include scalarization (because + ; <4 x double> is legalized to scalars). + ; CHECK: cost of 44 {{.*}} fcmp + %v1 = fcmp ugt <4 x double> undef, undef + + ret void +} + -- 2.11.0