Skip to content

Remove "unreachable" instruction from LLVM IR for SYCL devices #1789

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 11 commits into from
Jun 10, 2020

Conversation

srividya-sundaram
Copy link
Contributor

@srividya-sundaram srividya-sundaram commented Jun 1, 2020

C/C++ standard functions with __attribute__ ((__noreturn__)) in SYCL device code emit "unreachable" instruction in LLVM IR. This PR removes the "ur" instruction in LLVM IR for SYCL devices.

@Fznamznon Fznamznon requested a review from asavonic June 1, 2020 19:07
@erichkeane
Copy link
Contributor

@Savonic: Mind taking 1 more look? I'm going to approve, but I want your final thought as well.

Copy link
Contributor

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

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

Actually, I just realized there isn't a test here. Please add a CodeGen LIT test for this.

@bader
Copy link
Contributor

bader commented Jun 2, 2020

C/C++ standard functions with __attribute__ ((__noreturn__)) in SYCL device code emit "unreachable" instruction in LLVM IR. This "unreachable" instruction causes Intel NEO driver and Gen "X" GPUs to hang.

Isn't this expected behavior? Maybe I don't understand the behavior of this attribute it looks like if I call "noreturn" function, it might run forever. Right?

@erichkeane
Copy link
Contributor

C/C++ standard functions with __attribute__ ((__noreturn__)) in SYCL device code emit "unreachable" instruction in LLVM IR. This "unreachable" instruction causes Intel NEO driver and Gen "X" GPUs to hang.

Isn't this expected behavior? Maybe I don't understand the behavior of this attribute it looks like if I call "noreturn" function, it might run forever. Right?

Well, simply that the function doesn't 'return', and the optimizer is allowed to assume that it is a 'terminate' type of thing. Typically, a noreturn function must terminate the program (as never-ending loops are considered UB).

I forget the context of the bug report, but my understanding is that the driver folks didn't have a mechanism for handling this in the case of abort. Presumably, they would need to teach said drivers to abort, but I thought there wasn't a good way to do so.

Copy link
Contributor

@Fznamznon Fznamznon left a comment

Choose a reason for hiding this comment

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

BTW, please add a test.

@Fznamznon Fznamznon requested a review from asavonic June 2, 2020 17:18
@bader
Copy link
Contributor

bader commented Jun 2, 2020

C/C++ standard functions with __attribute__ ((__noreturn__)) in SYCL device code emit "unreachable" instruction in LLVM IR. This "unreachable" instruction causes Intel NEO driver and Gen "X" GPUs to hang.

Isn't this expected behavior? Maybe I don't understand the behavior of this attribute it looks like if I call "noreturn" function, it might run forever. Right?

Well, simply that the function doesn't 'return', and the optimizer is allowed to assume that it is a 'terminate' type of thing. Typically, a noreturn function must terminate the program (as never-ending loops are considered UB).

I forget the context of the bug report, but my understanding is that the driver folks didn't have a mechanism for handling this in the case of abort. Presumably, they would need to teach said drivers to abort, but I thought there wasn't a good way to do so.

Is code comments below captures it right?

void foo() { while(1); } // UB
[[noreturn]] void foo() { while(1); } // must terminate - not UB

@erichkeane
Copy link
Contributor

C/C++ standard functions with __attribute__ ((__noreturn__)) in SYCL device code emit "unreachable" instruction in LLVM IR. This "unreachable" instruction causes Intel NEO driver and Gen "X" GPUs to hang.

Isn't this expected behavior? Maybe I don't understand the behavior of this attribute it looks like if I call "noreturn" function, it might run forever. Right?

Well, simply that the function doesn't 'return', and the optimizer is allowed to assume that it is a 'terminate' type of thing. Typically, a noreturn function must terminate the program (as never-ending loops are considered UB).
I forget the context of the bug report, but my understanding is that the driver folks didn't have a mechanism for handling this in the case of abort. Presumably, they would need to teach said drivers to abort, but I thought there wasn't a good way to do so.

Is code comments below captures it right?

void foo() { while(1); } // UB
[[noreturn]] void foo() { while(1); } // must terminate - not UB

Infinite loops themselves are UB, see http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1528.htm

By my reading of the standard, BOTH while loops there are UB. I don't believe that the noreturn attribute changes that at all. It simply means that the compiler can optimize assuming that code after the call to a no-return function never executes.

@srividya-sundaram srividya-sundaram requested a review from a team as a code owner June 7, 2020 01:41
@srividya-sundaram srividya-sundaram requested a review from rbegam June 7, 2020 01:41
Copy link
Contributor

@Fznamznon Fznamznon left a comment

Choose a reason for hiding this comment

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

I'm fine with FE changes, but I'd like @asavonic to approve first since I'm not an expert in stuff which is happening in assert test.

asavonic
asavonic previously approved these changes Jun 9, 2020
Fznamznon
Fznamznon previously approved these changes Jun 9, 2020
@asavonic
Copy link
Contributor

asavonic commented Jun 9, 2020

Please align the PR title with the latest revision of the patch. It is no longer limited to Intel NEO driver.

@srividya-sundaram srividya-sundaram changed the title Remove "unreachable" instruction from LLVM IR for Intel NEO driver and Gen "X" GPUs Remove "unreachable" instruction from LLVM IR for SYCL devices Jun 9, 2020
@srividya-sundaram
Copy link
Contributor Author

@rbegam @intel/llvm-reviewers-runtime Can you please review this PR?

alexbatashev
alexbatashev previously approved these changes Jun 9, 2020
Copy link
Contributor

@alexbatashev alexbatashev left a comment

Choose a reason for hiding this comment

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

LGTM

@bader bader merged commit 74aa9a0 into intel:sycl Jun 10, 2020
@srividya-sundaram srividya-sundaram deleted the unreachable-inst-neo branch June 10, 2020 16:38
asavonic pushed a commit to asavonic/intel-llvm that referenced this pull request Jul 27, 2020
This is a follow-up to:
74aa9a0 [SYCL] Remove "unreachable" instruction from LLVM IR for SYCL
devices (intel#1789)

Noreturn function attribute gives LLVM optimization passes an
opportunity to re-structure code and insert an unreachable
instruction.

This happens when optimizations are turned on by
-fsycl-enable-optimizations, so noreturn function attribute must be
removed.

Signed-off-by: Andrew Savonichev <[email protected]>
bader pushed a commit that referenced this pull request Jul 28, 2020
This is a follow-up to:
74aa9a0 [SYCL] Remove "unreachable" instruction from LLVM IR for SYCL
devices (#1789)

Noreturn function attribute gives LLVM optimization passes an
opportunity to re-structure code and insert an unreachable
instruction.

This happens when optimizations are turned on by
-fsycl-enable-optimizations, so noreturn function attribute must be
removed.

Signed-off-by: Andrew Savonichev <[email protected]>
bb-sycl pushed a commit that referenced this pull request Jan 18, 2023
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.

7 participants