Skip to content

Commit c08f34e

Browse files
committed
[LoongArch] Override cost hooks to expose more DAG combine opportunities
1 parent 4621e17 commit c08f34e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9094,3 +9094,20 @@ bool LoongArchTargetLowering::SimplifyDemandedBitsForTargetNode(
90949094
return TargetLowering::SimplifyDemandedBitsForTargetNode(
90959095
Op, OriginalDemandedBits, OriginalDemandedElts, Known, TLO, Depth);
90969096
}
9097+
9098+
bool LoongArchTargetLowering::isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
9099+
unsigned Index) const {
9100+
if (!isOperationLegalOrCustom(ISD::EXTRACT_SUBVECTOR, ResVT))
9101+
return false;
9102+
9103+
// Extract a 128-bit subvector from index 0 of a 256-bit vector is free.
9104+
return Index == 0;
9105+
}
9106+
9107+
bool LoongArchTargetLowering::isExtractVecEltCheap(EVT VT,
9108+
unsigned Index) const {
9109+
EVT EltVT = VT.getScalarType();
9110+
9111+
// Extract a scalar FP value from index 0 of a vector is free.
9112+
return (EltVT == MVT::f32 || EltVT == MVT::f64) && Index == 0;
9113+
}

llvm/lib/Target/LoongArch/LoongArchISelLowering.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ class LoongArchTargetLowering : public TargetLowering {
332332
TargetLoweringOpt &TLO,
333333
unsigned Depth) const override;
334334

335+
bool isExtractSubvectorCheap(EVT ResVT, EVT SrcVT,
336+
unsigned Index) const override;
337+
bool isExtractVecEltCheap(EVT VT, unsigned Index) const override;
338+
335339
private:
336340
/// Target-specific function used to lower LoongArch calling conventions.
337341
typedef bool LoongArchCCAssignFn(const DataLayout &DL, LoongArchABI::ABI ABI,

0 commit comments

Comments
 (0)