Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions llvm/include/llvm/CodeGen/GlobalISel/GIMatchTableExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGenTypes/LowLevelType.h"
#include "llvm/IR/Function.h"
#include "llvm/Transforms/Utils/SizeOpts.h"
#include <bitset>
#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -635,8 +636,12 @@ class GIMatchTableExecutor {

bool shouldOptForSize(const MachineFunction *MF) const {
Copy link
Contributor

@kyulee-com kyulee-com Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is from your change, but it's a bit confusing how shouldOptForSize differs from llvm::shouldOptimizeForSize. I guess this is specifically used for GISel, and as long as the current processing block is optimized for size, we consider this function optimized for size? But don't we derive this check for a block by checking its parent function? Basically, my understanding is that even if shouldOptimizeForSize for a function is false, shouldOptimizeForSize for a block that belongs to the function may be true. Here, it doesn't seem like that's the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I would like to remove this too, but this caused some build errors because of generated code. In fact, some implementors don't even check PGO.

bool shouldOptForSize(const MachineFunction *MF) const {
// TODO: Implement PGSO.
return MF->getFunction().hasOptSize();
}

Since I'm less familiar with ISel, I thought I'd leave this alone for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that ISel generally prioritizes optimization for size. Since the shouldOptForSize derives its result from the current processing block, the outcome may not be consistent depending on which blocks are being processed, which is counterintuitive.
Upon examining another usage of DAGISel below, I believe this API is actually asking whether the current function should be optimized for size based on the current processing block or DAG.

bool shouldOptForSize(const MachineFunction *MF) const {
return CurDAG->shouldOptForSize();
}

So, we should keep this way on this context.

const auto &F = MF->getFunction();
return F.hasOptSize() || F.hasMinSize() ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lost the hasMinSize check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above (but got lost in the changes), F.hasOptSize() already calls hasMinSize().

bool hasOptSize() const {
return hasFnAttribute(Attribute::OptimizeForSize) || hasMinSize();
}

(PSI && BFI && CurMBB && llvm::shouldOptForSize(*CurMBB, PSI, BFI));
if (F.hasOptSize())
return true;
if (CurMBB)
if (auto *BB = CurMBB->getBasicBlock())
return llvm::shouldOptimizeForSize(BB, PSI, BFI);
return false;
}

public:
Expand Down
4 changes: 0 additions & 4 deletions llvm/include/llvm/CodeGen/GlobalISel/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,10 +542,6 @@ bool isConstFalseVal(const TargetLowering &TLI, int64_t Val, bool IsVector,
/// TargetBooleanContents.
int64_t getICmpTrueVal(const TargetLowering &TLI, bool IsVector, bool IsFP);

/// Returns true if the given block should be optimized for size.
bool shouldOptForSize(const MachineBasicBlock &MBB, ProfileSummaryInfo *PSI,
BlockFrequencyInfo *BFI);

using SmallInstListTy = GISelWorkList<4>;
void saveUsesAndErase(MachineInstr &MI, MachineRegisterInfo &MRI,
LostDebugLocObserver *LocObserver,
Expand Down
5 changes: 0 additions & 5 deletions llvm/lib/CodeGen/GlobalISel/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,11 +1619,6 @@ int64_t llvm::getICmpTrueVal(const TargetLowering &TLI, bool IsVector,
llvm_unreachable("Invalid boolean contents");
}

bool llvm::shouldOptForSize(const MachineBasicBlock &MBB,
ProfileSummaryInfo *PSI, BlockFrequencyInfo *BFI) {
return llvm::shouldOptimizeForSize(MBB.getBasicBlock(), PSI, BFI);
}

void llvm::saveUsesAndErase(MachineInstr &MI, MachineRegisterInfo &MRI,
LostDebugLocObserver *LocObserver,
SmallInstListTy &DeadInstChain) {
Expand Down
Loading