Skip to content

Fix several bugs#129

Merged
cfallin merged 4 commits intobytecodealliance:mainfrom
Amanieu:fix-3regclass
Apr 30, 2023
Merged

Fix several bugs#129
cfallin merged 4 commits intobytecodealliance:mainfrom
Amanieu:fix-3regclass

Conversation

@Amanieu
Copy link
Contributor

@Amanieu Amanieu commented Apr 30, 2023

This PR fixes 3 issues:

  • PReg::class was broken by Add a third register class #126.
  • PRegSet needs more than 128 bits for 3 register classes.
  • impl Display for Operand was incorrect for fixed-non-allocatable operands.

Amanieu added 2 commits April 30, 2023 03:34
These were previous displayed as a Use with a very large vreg number.
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Thanks! Just a few requests below but basically looks good.

src/lib.rs Outdated
debug_assert!(reg.index() < 256);
let bit = reg.index() & 127;
let index = reg.index() >> 7;
self.bits[index] & 1u128 << bit != 0
Copy link
Member

Choose a reason for hiding this comment

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

This is correct wrt operator precedence but it causes me to pause for a moment -- for easier mental parsing, could we add parens around 1u128 << bit ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

let index = reg.index() >> 7;
let mut out = self;
out.bits[index] |= 1u128 << bit;
out
Copy link
Member

Choose a reason for hiding this comment

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

Now that this logic has become slightly more complex, perhaps we could delegate to add with something like

let mut out = self;
out.add(reg);
out

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that at first, but it's not possible since with is a const fn. add can't be made const because it uses &mut self.

#[inline(always)]
pub const fn class(self) -> RegClass {
match self.bits & (0b11 << Self::MAX_BITS) {
match (self.bits >> Self::MAX_BITS) & 0b11 {
Copy link
Member

Choose a reason for hiding this comment

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

And, yikes, thanks for catching this -- sorry I missed it in review!

Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Thanks!

@cfallin cfallin merged commit 644113b into bytecodealliance:main Apr 30, 2023
Amanieu added a commit to Amanieu/regalloc2 that referenced this pull request May 1, 2023
This contains the bug fixes from bytecodealliance#129.
@Amanieu Amanieu mentioned this pull request May 1, 2023
cfallin pushed a commit that referenced this pull request May 1, 2023
This contains the bug fixes from #129.
@Amanieu Amanieu deleted the fix-3regclass branch November 24, 2023 08:47
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.

2 participants