Skip to content

C++ IR: Don't propagate GVN through non-exact Copy #1568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2019

Conversation

jbj
Copy link
Contributor

@jbj jbj commented Jul 9, 2019

The ValueNumbering library is supposed to propagate value numberings through a CopyInstruction only when it's congruent, meaning it must have exact overlap with its source. A CopyInstruction can be a LoadInstruction, a StoreInstruction, or a CopyValueInstruction. The latter is also a UnaryInstruction, and the value numbering rule for UnaryInstruction applied to it as well.

This meant that value numbering would propagate even through a non-congruent CopyValueInstruction. That's semantically wrong but probably only an issue in very rare circumstances, and it should get corrected when we change the definition of getUnary to require congruence.

What's worse is the performance implications. It meant that the value numbering IPA witness could take two different paths through every CopyValueInstruction. If multiple CopyValueInstructions were chained, this would lead to an exponential number of variable numbers for the same Instruction, and we would run out of time and space while performing value numbering.

This fixes the performance of ValueNumbering.qll on https://github.com/asterisk/asterisk, although this project might also require #1567.

The `ValueNumbering` library is supposed to propagate value numberings
through a `CopyInstruction` only when it's _congruent_, meaning it must
have exact overlap with its source. A `CopyInstruction` can be a
`LoadInstruction`, a `StoreInstruction`, or a `CopyValueInstruction`.
The latter is also a `UnaryInstruction`, and the value numbering rule
for `UnaryInstruction` applied to it as well.

This meant that value numbering would propagate even through a
non-congruent `CopyValueInstruction`. That's semantically wrong but
probably only an issue in very rare circumstances, and it should get
corrected when we change the definition of `getUnary` to require
congruence.

What's worse is the performance implications. It meant that the value
numbering IPA witness could take two different paths through every
`CopyValueInstruction`. If multiple `CopyValueInstruction`s were
chained, this would lead to an exponential number of variable numbers
for the same `Instruction`, and we would run out of time and space
while performing value numbering.

This fixes the performance of `ValueNumbering.qll` on
https://github.com/asterisk/asterisk, although this project might also
require a separate change for fixing an infinite loop in the IR constant
analysis.
@jbj jbj added the C++ label Jul 9, 2019
@jbj jbj requested a review from dave-bartolomeo July 9, 2019 09:07
@jbj jbj requested a review from a team as a code owner July 9, 2019 09:07
@dave-bartolomeo dave-bartolomeo merged commit ad5a16e into github:master Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants