Skip to content
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

codegen: add handling for undefined phinode values #45155

Merged
merged 1 commit into from
May 11, 2022
Merged

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented May 2, 2022

The optimization pass often uses values for phi values (and thus by
extension, also for pi, phic and upsilon values) that are invalid. We
make sure that these have a null pointer, so that we can detect that
case at runtime (at the cost of slightly worse code generation for
them), but it means we need to be very careful to check for that.

This is identical to #39747, which added the equivalent code to the
other side of the conditional there, but missed some additional
relevant, but rare, cases that are observed to be possible.

The emit_isa_and_defined is derived from the LLVM name for this
operation: isa_and_nonnull<T>.

Secondly, we also optimize emit_unionmove to change a bad IR case to a
better IR form.

Fix #44501

@vtjnash vtjnash added backport 1.6 Change should be backported to release-1.6 backport 1.7 backport 1.8 Change should be backported to release-1.8 compiler:codegen Generation of LLVM IR and native code labels May 2, 2022
@KristofferC
Copy link
Member

I pushed a test to this.


mktemp() do f_44501, _
write(f_44501, str_44501)
@test success(`$(Base.julia_cmd()) --startup-file=no -O0 $f_44501`)
Copy link
Member Author

Choose a reason for hiding this comment

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

why is this launching a process to run a test? we don't do that normally

Copy link
Member

Choose a reason for hiding this comment

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

Because it needs -O0 to repro.

Copy link
Member Author

Choose a reason for hiding this comment

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

That generally just means it is a bad test, but you don't need a new process for that either as there is Base.Experimental.@compiler_options optimize=0

Copy link
Member

Choose a reason for hiding this comment

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

It's the test I have for now. I'll try with the option instead, good idea.

Copy link
Member

Choose a reason for hiding this comment

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

I tried with that but it didn't repro with it. Feel free to change/remove this test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ultimately our ssa-conversion optimization pass is doing a bad job here, so this test is not expected to be reliable. We don't really have a good way to unit-test just the codegen part however for weird IR forms like this.

The optimization pass often uses values for phi values (and thus by
extension, also for pi, phic and upsilon values) that are invalid. We
make sure that these have a null pointer, so that we can detect that
case at runtime (at the cost of slightly worse code generation for
them), but it means we need to be very careful to check for that.

This is identical to #39747, which added the equivalent code to the
other side of the conditional there, but missed some additional
relevant, but rare, cases that are observed to be possible.

The `emit_isa_and_defined` is derived from the LLVM name for this
operation: `isa_and_nonnull<T>`.

Secondly, we also optimize `emit_unionmove` to change a bad IR case to a
better IR form.

Fix #44501
@vtjnash vtjnash added DO NOT MERGE Do not merge this PR! merge me PR is reviewed. Merge when all tests are passing and removed DO NOT MERGE Do not merge this PR! labels May 9, 2022
@oscardssmith oscardssmith merged commit 72b80e2 into master May 11, 2022
@oscardssmith oscardssmith deleted the jn/44501 branch May 11, 2022 15:24
@giordano giordano removed the merge me PR is reviewed. Merge when all tests are passing label May 13, 2022
KristofferC pushed a commit that referenced this pull request May 16, 2022
The optimization pass often uses values for phi values (and thus by
extension, also for pi, phic and upsilon values) that are invalid. We
make sure that these have a null pointer, so that we can detect that
case at runtime (at the cost of slightly worse code generation for
them), but it means we need to be very careful to check for that.

This is identical to #39747, which added the equivalent code to the
other side of the conditional there, but missed some additional
relevant, but rare, cases that are observed to be possible.

The `emit_isa_and_defined` is derived from the LLVM name for this
operation: `isa_and_nonnull<T>`.

Secondly, we also optimize `emit_unionmove` to change a bad IR case to a
better IR form.

Fix #44501

(cherry picked from commit 72b80e2)
KristofferC pushed a commit that referenced this pull request May 18, 2022
The optimization pass often uses values for phi values (and thus by
extension, also for pi, phic and upsilon values) that are invalid. We
make sure that these have a null pointer, so that we can detect that
case at runtime (at the cost of slightly worse code generation for
them), but it means we need to be very careful to check for that.

This is identical to #39747, which added the equivalent code to the
other side of the conditional there, but missed some additional
relevant, but rare, cases that are observed to be possible.

The `emit_isa_and_defined` is derived from the LLVM name for this
operation: `isa_and_nonnull<T>`.

Secondly, we also optimize `emit_unionmove` to change a bad IR case to a
better IR form.

Fix #44501

(cherry picked from commit 72b80e2)
@KristofferC KristofferC removed the backport 1.8 Change should be backported to release-1.8 label May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.6 Change should be backported to release-1.6 compiler:codegen Generation of LLVM IR and native code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segfault in collect in HierarchialUtilities
4 participants