[CodeGen][NFC] Compute MaximumLegalStoreInBits just once (#189355)

Instead of iterating over all value types per basic block, pre-compute
the TLI-specific value once when constructing the TLI.
This commit is contained in:
Alexis Engelke 2026-03-30 18:44:18 +02:00 committed by GitHub
parent 0151d56324
commit bbef10d9f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 15 deletions

View File

@ -2084,6 +2084,12 @@ public:
/// Retuen the minimum of largest number of comparisons in BitTest.
unsigned getMinimumBitTestCmps() const;
/// Return maximum known-legal store size, which can be guaranteed for
/// scalable vectors.
unsigned getMaximumLegalStoreInBits() const {
return MaximumLegalStoreInBits;
}
/// If a physical register, this specifies the register that
/// llvm.savestack/llvm.restorestack should save and restore.
Register getStackPointerRegisterToSaveRestore() const {
@ -3767,6 +3773,10 @@ private:
/// The minimum of largest number of comparisons to use bit test for switch.
unsigned MinimumBitTestCmps;
/// Maximum known-legal store size, which can be guaranteed for scalable
/// vectors.
unsigned MaximumLegalStoreInBits;
/// This indicates if the target supports unaligned atomic operations.
bool SupportsUnalignedAtomics;

View File

@ -260,15 +260,6 @@ namespace {
ForCodeSize = DAG.shouldOptForSize();
DisableGenericCombines =
DisableCombines || (STI && STI->disableGenericCombines(OptLevel));
MaximumLegalStoreInBits = 0;
// We use the minimum store size here, since that's all we can guarantee
// for the scalable vector types.
for (MVT VT : MVT::all_valuetypes())
if (EVT(VT).isSimple() && VT != MVT::Other &&
TLI.isTypeLegal(EVT(VT)) &&
VT.getSizeInBits().getKnownMinValue() >= MaximumLegalStoreInBits)
MaximumLegalStoreInBits = VT.getSizeInBits().getKnownMinValue();
}
void ConsiderForPruning(SDNode *N) {
@ -344,8 +335,6 @@ namespace {
void CommitTargetLoweringOpt(const TargetLowering::TargetLoweringOpt &TLO);
private:
unsigned MaximumLegalStoreInBits;
/// Check the specified integer node value to see if it can be simplified or
/// if things it uses can be simplified by bit propagation.
/// If so, return true.
@ -22719,7 +22708,7 @@ bool DAGCombiner::tryStoreMergeOfConstants(
unsigned IsFast = 0;
// Break early when size is too large to be legal.
if (StoreTy.getSizeInBits() > MaximumLegalStoreInBits)
if (StoreTy.getSizeInBits() > TLI.getMaximumLegalStoreInBits())
break;
if (TLI.isTypeLegal(StoreTy) &&
@ -22827,7 +22816,7 @@ bool DAGCombiner::tryStoreMergeOfExtracts(
unsigned IsFast = 0;
// Break early when size is too large to be legal.
if (Ty.getSizeInBits() > MaximumLegalStoreInBits)
if (Ty.getSizeInBits() > TLI.getMaximumLegalStoreInBits())
break;
if (TLI.isTypeLegal(Ty) &&
@ -22974,7 +22963,7 @@ bool DAGCombiner::tryStoreMergeOfLoads(SmallVectorImpl<MemOpLink> &StoreNodes,
EVT StoreTy = EVT::getVectorVT(Context, MemVT.getScalarType(), Elts);
// Break early when size is too large to be legal.
if (StoreTy.getSizeInBits() > MaximumLegalStoreInBits)
if (StoreTy.getSizeInBits() > TLI.getMaximumLegalStoreInBits())
break;
unsigned IsFastSt = 0;
@ -23194,7 +23183,8 @@ bool DAGCombiner::mergeConsecutiveStores(StoreSDNode *St) {
EVT MemVT = St->getMemoryVT();
if (MemVT.isScalableVT())
return false;
if (!MemVT.isSimple() || MemVT.getSizeInBits() * 2 > MaximumLegalStoreInBits)
if (!MemVT.isSimple() ||
MemVT.getSizeInBits() * 2 > TLI.getMaximumLegalStoreInBits())
return false;
// This function cannot currently deal with non-byte-sized memory sizes.

View File

@ -1939,6 +1939,13 @@ void TargetLoweringBase::computeRegisterProperties(
RepRegClassForVT[i] = RRC;
RepRegClassCostForVT[i] = Cost;
}
// Compute minimum known-legal store size.
MaximumLegalStoreInBits = 0;
for (MVT VT : MVT::all_valuetypes())
if (VT != MVT::Other && isTypeLegal(VT) &&
VT.getSizeInBits().getKnownMinValue() >= MaximumLegalStoreInBits)
MaximumLegalStoreInBits = VT.getSizeInBits().getKnownMinValue();
}
EVT TargetLoweringBase::getSetCCResultType(const DataLayout &DL, LLVMContext &,