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 bug with Base.lshr_int intrinsic #37880

Closed
rfourquet opened this issue Oct 4, 2020 · 3 comments · Fixed by #37891
Closed

Codegen bug with Base.lshr_int intrinsic #37880

rfourquet opened this issue Oct 4, 2020 · 3 comments · Fixed by #37891
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior compiler:codegen Generation of LLVM IR and native code

Comments

@rfourquet
Copy link
Member

Ref: https://discourse.julialang.org/t/failure-with-lshr-int-intrinsic-for-on-uint256-type/47738/4
@simeonschaub suggested this repro which "looks like it’s an LLVM bug":

julia> primitive type UInt256 256 end

julia> x = reinterpret(UInt256, rand(UInt128, 2))[]
UInt256(0x48805fdfb72d71fadaf8daa563cf816383f755d9d9e70d703fa348f556c717ad)

julia> f(x) = Base.lshr_int(x, 0x8)
f (generic function with 1 method)

julia> @code_llvm optimize=false f(x)
;  @ REPL[22]:1 within `f'
define void @julia_f_392(i256* noalias nocapture sret %0, i256 %1) {
top:
  %2 = call {}*** @julia.ptls_states()
  %3 = bitcast {}*** %2 to {}**
  %4 = getelementptr inbounds {}*, {}** %3, i64 4
  %5 = bitcast {}** %4 to i64**
  %6 = load i64*, i64** %5
  %7 = lshr i256 %1, 8
  %8 = select i1 true, i256 0, i256 %7
  store i256 %8, i256* %0, align 8
  ret void
}

julia> @code_llvm optimize=true f(x)
;  @ REPL[22]:1 within `f'
define void @julia_f_394(i256* noalias nocapture sret %0, i256 %1) {
top:
  store i256 0, i256* %0, align 8
  ret void
}
@yuyichao
Copy link
Contributor

yuyichao commented Oct 4, 2020

This is not an LLVM bug but a codegen bug (as the unoptimized version shows). The check for overflow should check the size of the shift amount. If the size of the value (in this case 256) doesn't fit in the shift size (i8) the check should simply be omitted since there's no way the shift can overflow.

@yuyichao yuyichao changed the title LLVM bug with Base.lshr_int intrinsic Codegen bug with Base.lshr_int intrinsic Oct 4, 2020
@yuyichao yuyichao added the compiler:codegen Generation of LLVM IR and native code label Oct 4, 2020
@StefanKarpinski
Copy link
Member

@Keno, would you be an appropriate person to take a look at this?

@JeffBezanson
Copy link
Member

I'll fix it.

@JeffBezanson JeffBezanson self-assigned this Oct 5, 2020
@JeffBezanson JeffBezanson added the bug Indicates an unexpected problem or unintended behavior label Oct 5, 2020
KristofferC pushed a commit that referenced this issue Oct 21, 2020
KristofferC pushed a commit that referenced this issue Oct 21, 2020
@vchuravy vchuravy mentioned this issue Jan 21, 2021
27 tasks
vchuravy pushed a commit that referenced this issue Jan 22, 2021
vchuravy pushed a commit that referenced this issue Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior compiler:codegen Generation of LLVM IR and native code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants