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

Annotate function arguments with sext/zext #39051

Merged
merged 2 commits into from
Jan 7, 2021
Merged

Annotate function arguments with sext/zext #39051

merged 2 commits into from
Jan 7, 2021

Conversation

vchuravy
Copy link
Member

https://bugs.llvm.org/show_bug.cgi?id=30451#c11 pointed out that we
need to annotate the parameters of functions with sext/zext so that
the backend can use the right semantics when promoting from a narrower type
to a register type. We do this for ccall (x-ref: #978) already, but it seems
like we need to do this generally.

Does anybody know if there are other places I might need to add this?

@vchuravy vchuravy added backport 1.6 Change should be backported to release-1.6 compiler:codegen Generation of LLVM IR and native code system:powerpc PowerPC labels Dec 30, 2020
@vchuravy vchuravy requested review from Keno and vtjnash December 30, 2020 20:56
@vtjnash
Copy link
Member

vtjnash commented Dec 30, 2020

Sounds like an LLVM bug in the PPC backend. It's okay for it to use anyext in the target lowering only because the bits are undef. But the PPC backend codegen is treating them as if they were defined (e.g. missing a trunc & sext before the atomicrmw to legalize the register content)

@Keno
Copy link
Member

Keno commented Dec 30, 2020

I concur with @vtjnash's analysis.

@Keno
Copy link
Member

Keno commented Dec 30, 2020

Doesn't mean that we shouldn't do this also though. Would probably save a few unnecessary instructions in a few places.

@vchuravy
Copy link
Member Author

@nemanjai do you have any comments?

@vchuravy
Copy link
Member Author

vchuravy commented Jan 4, 2021

Doesn't mean that we shouldn't do this also though.

Good to merge then?

@nemanjai
Copy link

nemanjai commented Jan 4, 2021

LGTM.

@Keno
Copy link
Member

Keno commented Jan 4, 2021

The PowerPC backend should still be fixed independently. Frankly, I'd prefer for that to happen first before we merge this, since otherwise we risk hiding the bug here. There's nothing preventing a signed comparison with an unsigned type, which would exhibit the exact same symptoms, but with this PR applied the bug is hidden.

@vtjnash vtjnash added the upstream The issue is with an upstream dependency, e.g. LLVM label Jan 4, 2021
@vtjnash
Copy link
Member

vtjnash commented Jan 4, 2021

I think we could write a test to show that case too, by passing in a UInt16 and then reinterpreting it as Int16 before the atomic op. But likely easier to show with an llvm unit test.

@Keno
Copy link
Member

Keno commented Jan 4, 2021

Sure, if @vchuravy wants to add that test, I'm happy to merge this ;).

@vchuravy
Copy link
Member Author

vchuravy commented Jan 6, 2021

I will merge this once CI is green. Upstream PR for the PPC backend is https://reviews.llvm.org/D94058

@vchuravy vchuravy merged commit 34ab0a9 into master Jan 7, 2021
@vchuravy vchuravy deleted the vc/sext branch January 7, 2021 18:56
@vchuravy
Copy link
Member Author

backported in #39160

@vchuravy vchuravy removed the backport 1.6 Change should be backported to release-1.6 label Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code system:powerpc PowerPC upstream The issue is with an upstream dependency, e.g. LLVM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants