From 5797feaa55bceda38ed797de7ad90ecd6d2ee222 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 25 Mar 2021 14:20:38 -0700 Subject: [PATCH] [RISCV] Reorder checks in RISCVTTIImpl::getGatherScatterOpCost to avoid calling getMinRVVVectorSizeInBits() when V extension is not enabled. getMinRVVVectorSizeInBits() asserts if the V extension isn't enabled. So check that gather/scatter is legal first since it already contains a check for V extension being enabled. It also already checks getMinRVVVectorSizeInBits for fixed length vectors so we don't need a check in getGatherScatterOpCost. --- llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp | 10 +++++----- .../Analysis/CostModel/RISCV/fixed-vector-gather.ll | 2 ++ .../Analysis/CostModel/RISCV/fixed-vector-scatter.ll | 2 ++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp index ab80b18d12c2..f1c6d5630c83 100644 --- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp @@ -148,11 +148,6 @@ unsigned RISCVTTIImpl::getGatherScatterOpCost( return BaseT::getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask, Alignment, CostKind, I); - // FIXME: Only supporting fixed vectors for now. - if (!isa(DataTy) || ST->getMinRVVVectorSizeInBits() == 0) - return BaseT::getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask, - Alignment, CostKind, I); - if ((Opcode == Instruction::Load && !isLegalMaskedGather(DataTy, Align(Alignment))) || (Opcode == Instruction::Store && @@ -160,6 +155,11 @@ unsigned RISCVTTIImpl::getGatherScatterOpCost( return BaseT::getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask, Alignment, CostKind, I); + // FIXME: Only supporting fixed vectors for now. + if (!isa(DataTy)) + return BaseT::getGatherScatterOpCost(Opcode, DataTy, Ptr, VariableMask, + Alignment, CostKind, I); + auto *VTy = cast(DataTy); unsigned NumLoads = VTy->getNumElements(); unsigned MemOpCost = diff --git a/llvm/test/Analysis/CostModel/RISCV/fixed-vector-gather.ll b/llvm/test/Analysis/CostModel/RISCV/fixed-vector-gather.ll index a456c95313c3..5de1f3eb97d8 100644 --- a/llvm/test/Analysis/CostModel/RISCV/fixed-vector-gather.ll +++ b/llvm/test/Analysis/CostModel/RISCV/fixed-vector-gather.ll @@ -1,5 +1,7 @@ ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py ; RUN: opt -cost-model -analyze -mtriple=riscv64 -mattr=+experimental-v,+f,+d,+experimental-zfh -riscv-v-vector-bits-min=128 -riscv-v-fixed-length-vector-lmul-max=1 < %s 2>%t | FileCheck %s +; Sanity check that we don't crash querying costs when vectors are not enabled. +; RUN: opt -cost-model -analyze -mtriple=riscv64 define i32 @masked_gather() { ; CHECK-LABEL: 'masked_gather' diff --git a/llvm/test/Analysis/CostModel/RISCV/fixed-vector-scatter.ll b/llvm/test/Analysis/CostModel/RISCV/fixed-vector-scatter.ll index 23f0fbd24afb..90323e26e8fa 100644 --- a/llvm/test/Analysis/CostModel/RISCV/fixed-vector-scatter.ll +++ b/llvm/test/Analysis/CostModel/RISCV/fixed-vector-scatter.ll @@ -1,5 +1,7 @@ ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py ; RUN: opt -cost-model -analyze -mtriple=riscv64 -mattr=+experimental-v,+f,+d,+experimental-zfh -riscv-v-vector-bits-min=128 -riscv-v-fixed-length-vector-lmul-max=1 < %s 2>%t | FileCheck %s +; Sanity check that we don't crash querying costs when vectors are not enabled. +; RUN: opt -cost-model -analyze -mtriple=riscv64 define i32 @masked_scatter() { ; CHECK-LABEL: 'masked_scatter'