[llvm] [RISCV][TTI] Add checks for invalid cast operations (PR #88854)
Shih-Po Hung via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 16 01:16:08 PDT 2024
https://github.com/arcbbb created https://github.com/llvm/llvm-project/pull/88854
In issue #88802, the LV cost model would query the cost of the TRUNC for source type 2xi1 and destination type 2xi32. This patch adds an early exit check to prevent invalid operations.
>From a5278c4275b0eaf2d8b2b331eca18a095d2eb628 Mon Sep 17 00:00:00 2001
From: ShihPo Hung <shihpo.hung at sifive.com>
Date: Tue, 16 Apr 2024 00:59:45 -0700
Subject: [PATCH] [RISCV][TTI] Add checks for invalid cast operations
In issue #88802, the LV cost model would query the cost of
the TRUNC for source type 2xi1 and destination type 2xi32.
This patch adds an early exit check to prevent invalid operations.
---
llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
index 38304ff90252f0..c4f1c275f63b65 100644
--- a/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp
@@ -956,6 +956,9 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
return getRISCVInstructionCost(Op, DstLT.second, CostKind);
}
case ISD::TRUNCATE:
+ // Early return for invalid operation
+ if (Dst->getScalarSizeInBits() >= Src->getScalarSizeInBits())
+ break;
if (Dst->getScalarSizeInBits() == 1) {
// We do not use several vncvt to truncate to mask vector. So we could
// not use PowDiff to calculate it.
@@ -968,6 +971,13 @@ InstructionCost RISCVTTIImpl::getCastInstrCost(unsigned Opcode, Type *Dst,
[[fallthrough]];
case ISD::FP_EXTEND:
case ISD::FP_ROUND: {
+ // Early return for invalid operation
+ if ((ISD == ISD::FP_ROUND) &&
+ Dst->getScalarSizeInBits() >= Src->getScalarSizeInBits())
+ break;
+ if ((ISD == ISD::FP_EXTEND) &&
+ Src->getScalarSizeInBits() >= Dst->getScalarSizeInBits())
+ break;
// Counts of narrow/widen instructions.
unsigned SrcEltSize = Src->getScalarSizeInBits();
unsigned DstEltSize = Dst->getScalarSizeInBits();
More information about the llvm-commits
mailing list