Index: llvm/lib/CodeGen/RegAllocGreedy.cpp =================================================================== --- llvm/lib/CodeGen/RegAllocGreedy.cpp +++ llvm/lib/CodeGen/RegAllocGreedy.cpp @@ -550,16 +550,19 @@ struct RAGreedyStats { unsigned Reloads = 0; unsigned FoldedReloads = 0; + unsigned ZeroCostFoldedReloads = 0; unsigned Spills = 0; unsigned FoldedSpills = 0; bool isEmpty() { - return !(Reloads || FoldedReloads || Spills || FoldedSpills); + return !(Reloads || FoldedReloads || Spills || FoldedSpills || + ZeroCostFoldedReloads); } void add(RAGreedyStats other) { Reloads += other.Reloads; FoldedReloads += other.FoldedReloads; + ZeroCostFoldedReloads += other.ZeroCostFoldedReloads; Spills += other.Spills; FoldedSpills += other.FoldedSpills; } @@ -3138,6 +3141,9 @@ R << NV("NumReloads", Reloads) << " reloads "; if (FoldedReloads) R << NV("NumFoldedReloads", FoldedReloads) << " folded reloads "; + if (ZeroCostFoldedReloads) + R << NV("NumZeroCostFoldedReloads", ZeroCostFoldedReloads) + << " zero cost folded reloads "; } RAGreedy::RAGreedyStats @@ -3156,9 +3162,24 @@ if (TII->isLoadFromStackSlot(MI, FI) && MFI.isSpillSlotObjectIndex(FI)) ++Stats.Reloads; else if (TII->hasLoadFromStackSlot(MI, Accesses) && - llvm::any_of(Accesses, isSpillSlotAccess)) - ++Stats.FoldedReloads; - else if (TII->isStoreToStackSlot(MI, FI) && MFI.isSpillSlotObjectIndex(FI)) + llvm::any_of(Accesses, isSpillSlotAccess)) { + if (MI.getOpcode() == TargetOpcode::PATCHPOINT || + MI.getOpcode() == TargetOpcode::STACKMAP || + MI.getOpcode() == TargetOpcode::STATEPOINT) { + std::pair NonZeroCostRange = + TII->getPatchpointUnfoldableRange(MI); + if (any_of(MI.operands(), [&](MachineOperand &MO) { + return MO.isFI() && MFI.isSpillSlotObjectIndex(MO.getIndex()) && + MI.getOperandNo(&MO) >= NonZeroCostRange.first && + MI.getOperandNo(&MO) < NonZeroCostRange.second; + })) + ++Stats.FoldedReloads; + else + ++Stats.ZeroCostFoldedReloads; + } else + ++Stats.FoldedReloads; + } else if (TII->isStoreToStackSlot(MI, FI) && + MFI.isSpillSlotObjectIndex(FI)) ++Stats.Spills; else if (TII->hasStoreToStackSlot(MI, Accesses) && llvm::any_of(Accesses, isSpillSlotAccess))