Skip to content

Conversation

F-Stuckmann
Copy link
Collaborator

This is a Non Functional Change to Move Immediate Checks from Instruction Selection to TII.
The global combiner PR (#405 ) needs this refactor, as well as #451 .

@@ -2469,13 +2470,11 @@ LoadStoreOpcodes AIE2InstructionSelector::getLoadStoreOpcode(
if (getLoadStoreSize(I) == 512) {
unsigned RBID = deriveRegBankID(I.getOperand(0).getReg(), MRI, RBI);
if (RBID == AIE2::AccRegBankID) {
FitsImmediateRange = checkImmediateRangeSplitting<6, 32, 32>(Offset);
Copy link
Collaborator

Choose a reason for hiding this comment

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

micronit: we now do the entire case analysis twice, once for the immediate range and once for the instruction selection.


template <unsigned NumEncodingBits, unsigned Step>
bool checkImmediateRange(std::optional<APInt> Immediate) {
unsigned MaxPow2 = NumEncodingBits + llvm::Log2_64(Step);
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about passing Log2_64(Step), so that both parameters have the same unit? I guess that computing pow2(StepBits) is cheaper than computing Log2(Step).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is not my code and this change would be nicely suited for a proper cleanup. Because we now have multiple switch cases that checkImmediateRanges

@@ -59,6 +59,10 @@ struct AIEBaseInstrInfo : public TargetInstrInfo {
// of bundles.
unsigned LoopSetupDistance;
};
virtual bool isOffsetInImmediateRange(unsigned Opcode, unsigned LoadStoreSize,
std::optional<APInt> Offset) const {
llvm_unreachable("Target didn't implement OffsetFitImmRange");
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: message out of sync with function name

@@ -59,6 +59,10 @@ struct AIEBaseInstrInfo : public TargetInstrInfo {
// of bundles.
unsigned LoopSetupDistance;
};
virtual bool isOffsetInImmediateRange(unsigned Opcode, unsigned LoadStoreSize,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a feeling that this may be a best guess for these generic opcodes. Perhaps document whether it should return true or false if there's uncertainty.

case 1024:
return checkSignedImmediateRangeSplitting<4, 64, 64>(Offset);
case 2048:
return checkSignedImmediateRangeSplitting<4, 64, 192>(Offset);
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I see that this checks 0 and 192, not the intermediate 64 and 128. I guess the implementation assumes that step divides splitoffset. Perhaps static_assert that?

Copy link
Collaborator

@martien-de-jong martien-de-jong left a comment

Choose a reason for hiding this comment

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

There will always be nits

@F-Stuckmann F-Stuckmann merged commit a58e351 into aie-public Jun 18, 2025
6 checks passed
@F-Stuckmann F-Stuckmann deleted the stuckmann.refactor.mem.imm.check branch July 18, 2025 13:04
mgehre-amd pushed a commit that referenced this pull request Aug 21, 2025
…ion_compare_with_different_bitwith

Also canonicalize select and geq with different width in integer types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants