Skip to content

Conversation

rbrchen
Copy link
Contributor

@rbrchen rbrchen commented Sep 2, 2025

Fix a bug in SSABraun where, in tryRemoveTrivialPhi(), a phi stored in same that is later deleted in a recursive tryRemoveTrivialPhi() call is still returned despite being deleted.

Add five tests to TestSSA: deadCode(), ifelseLoopNested(), violaJones(), binarySearch(), and quicksort(). violaJones() is inspired by the method findFeaturesKernel in HAT kernel ViolaJones, which is the bug first presented itself.


Progress

  • Change must not contain extraneous whitespace

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/babylon.git pull/542/head:pull/542
$ git checkout pull/542

Update a local copy of the PR:
$ git checkout pull/542
$ git pull https://git.openjdk.org/babylon.git pull/542/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 542

View PR using the GUI difftool:
$ git pr show -t 542

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/babylon/pull/542.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 2, 2025

👋 Welcome back rbrchen! A progress list of the required criteria for merging this PR into code-reflection will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Sep 2, 2025

@rbrchen This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

Fix SSABraun bug and add SSA tests

Reviewed-by: psandoz

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the code-reflection branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@PaulSandoz) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 2, 2025
@mlbridge
Copy link

mlbridge bot commented Sep 2, 2025

Webrevs

@SirYwell
Copy link
Member

SirYwell commented Sep 2, 2025

Hi, it's not obvious to me what the bug is. The replaceBy method has the user == this check; what's the difference to removing itself before? And is the returned list wrong, or why aren't you using it anymore?

@rbrchen
Copy link
Contributor Author

rbrchen commented Sep 2, 2025

Hi! Sorry about the confusion; I just realized this change doesn't actually fix the bug, and that the core of the problem lies in how the maps additionalParameters and loads update.

Your original code in tryRemoveTrivialPhi() was correct, but when a phi is added to additionalParameters and is later replaced by a parameter via replaceBy(), both additionalParameters and loads are not updated to keep track of the new parameter.

I can restore your code and implement those changes to make sure that the two maps replace deleted phis with appropriate values.

@rbrchen rbrchen marked this pull request as draft September 2, 2025 22:04
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 2, 2025
@SirYwell
Copy link
Member

SirYwell commented Sep 3, 2025

Interesting, thanks for the investigation!

A few pointers regarding the mentioned maps:

  • additionalParameters should only need removal at this point, as we don't need a block parameter for the new definition anymore
  • The loads are updated in replaceBy, but there might be cases where things go wrong there
  • There also is deletedPhis, which is supposed to correct lookups to instead look for a definition in the dominating blocks

These are the parts not present in the original algorithm due to (im)mutability, so I always suspected these to be the most fragile parts of the implementation. If you have any ideas to simplify these "workarounds", I'd be very happy :)

@rbrchen
Copy link
Contributor Author

rbrchen commented Sep 3, 2025

Thanks for the pointers! I'll circle back to this PR with any ideas and/or code changes for the maps :)

@rbrchen rbrchen marked this pull request as ready for review September 9, 2025 18:48
@openjdk openjdk bot added ready Pull request is ready to be integrated rfr Pull request is ready for review labels Sep 9, 2025
Copy link
Member

@SirYwell SirYwell left a comment

Choose a reason for hiding this comment

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

Okay I looked into this a bit closer now with your latest change, and I think it makes sense this way. Interestingly, the original implementation works slightly different than what's described in the paper https://github.com/libfirm/libfirm/blob/114012d1d93427e63ba2f2ab51318e8a1b92f06c/ir/ir/ircons.c#L6.
I wonder if this is an oversight in the algorithm described in the paper.

@rbrchen
Copy link
Contributor Author

rbrchen commented Sep 10, 2025

Thanks for looking it over! Yeah, I think it might've been an oversight in the paper's algorithm. Looking at the actual implementation right now, I see how they arrived at the paper's pseudocode, but it's interesting that the paper went ahead with those slight differences :')

@rbrchen
Copy link
Contributor Author

rbrchen commented Sep 11, 2025

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Sep 11, 2025
@openjdk
Copy link

openjdk bot commented Sep 11, 2025

@rbrchen
Your change (at version a2a723e) is now ready to be sponsored by a Committer.

@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Sep 11, 2025
@rbrchen
Copy link
Contributor Author

rbrchen commented Sep 11, 2025

/integrate

@openjdk
Copy link

openjdk bot commented Sep 11, 2025

@rbrchen Only Committers are allowed to sponsor changes.

@rbrchen
Copy link
Contributor Author

rbrchen commented Sep 11, 2025

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Sep 11, 2025
@openjdk
Copy link

openjdk bot commented Sep 11, 2025

@rbrchen
Your change (at version 0f1d75d) is now ready to be sponsored by a Committer.

Copy link
Member

@PaulSandoz PaulSandoz left a comment

Choose a reason for hiding this comment

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

Well done. We can investigate and address the use of identity equality in another PR, if necessary.

@PaulSandoz
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Sep 11, 2025

Going to push as commit ab94fe7.

@openjdk openjdk bot added the integrated Pull request has been integrated label Sep 11, 2025
@openjdk openjdk bot closed this Sep 11, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Sep 11, 2025
@openjdk
Copy link

openjdk bot commented Sep 11, 2025

@PaulSandoz @rbrchen Pushed as commit ab94fe7.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

3 participants