This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Prevent overflowing the small size of InstSeq in generateInstSeq.
ClosedPublic

Authored by craig.topper on Jun 6 2023, 1:50 PM.

Details

Summary

The small size is 8 which is the worst case of the core recursive
algorithm.

The special cases use the core algorithm and append additonal
instructions. We were pushing the extra instructions before checking
the profitability. This could lead to 9 and maybe 10 instructions
in the sequence which overflows the small size.

This patch does the profitability check before inserting the
extra instructions so that we don't create 9 or 10 insruction
sequences.

Alternative we could bump the small size to 9 or 10, but then
we're pushing things that are never going be used.

Diff Detail

Event Timeline

craig.topper created this revision.Jun 6 2023, 1:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 6 2023, 1:50 PM
craig.topper requested review of this revision.Jun 6 2023, 1:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 6 2023, 1:50 PM
asb accepted this revision.Jun 12 2023, 11:36 AM

Sorry for the slow review, I was mostly out / traveling last week.

The original logic was written to be dumb but easy to follow, and in the absence of benchmarking data I'd be tempted to just bump the size to keep the logic that way. But this change seems correct and I've got not real objection to it if it's your preferred approach.

This revision is now accepted and ready to land.Jun 12 2023, 11:36 AM

Sorry for the slow review, I was mostly out / traveling last week.

The original logic was written to be dumb but easy to follow, and in the absence of benchmarking data I'd be tempted to just bump the size to keep the logic that way. But this change seems correct and I've got not real objection to it if it's your preferred approach.

I'm not sure how to enforce the small size is sufficient if we do go that way. I was wondering if this sequence was a good candidate for the StaticVector proposed in https://reviews.llvm.org/D112175. I tried to make InstSeq into my own simplified static vector with a buffer of 8 and that's how I found the overflow.