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

@inbounds cannot be applied to entire functions #13234

Open
mauro3 opened this issue Sep 20, 2015 · 6 comments
Open

@inbounds cannot be applied to entire functions #13234

mauro3 opened this issue Sep 20, 2015 · 6 comments

Comments

@mauro3
Copy link
Contributor

mauro3 commented Sep 20, 2015

The documentation of @inbounds suggests that it can be applied to whole functions:
http://docs.julialang.org/en/release-0.4/manual/performance-tips/?highlight=inbounds#performance-annotations.

However this suggests that it does not work (similar on 0.3 and 0.4):

julia> @inbounds f(xs, i) = xs[i]

julia> g(xs, i) = @inbounds return xs[i]
g (generic function with 1 method)

julia> code_llvm(f, Tuple{Vector{Int}, Int})

define i64 @julia_f_21403(%jl_value_t*, i64) {
top:
  %2 = add i64 %1, -1
  %3 = getelementptr inbounds %jl_value_t* %0, i64 1
  %4 = bitcast %jl_value_t* %3 to i64*
  %5 = load i64* %4, align 8
  %6 = icmp ult i64 %2, %5
  br i1 %6, label %idxend, label %oob

oob:                                              ; preds = %top
  %7 = alloca i64, align 8
  store i64 %1, i64* %7, align 8
  call void @jl_bounds_error_ints(%jl_value_t* %0, i64* %7, i64 1)
  unreachable

idxend:                                           ; preds = %top
  %8 = bitcast %jl_value_t* %0 to i8**
  %9 = load i8** %8, align 8
  %10 = bitcast i8* %9 to i64*
  %11 = getelementptr i64* %10, i64 %2
  %12 = load i64* %11, align 8
  ret i64 %12
}

julia> code_llvm(g, Tuple{Vector{Int}, Int})

define i64 @julia_g_21404(%jl_value_t*, i64) {
top:
  %2 = add i64 %1, -1
  %3 = bitcast %jl_value_t* %0 to i8**
  %4 = load i8** %3, align 8
  %5 = bitcast i8* %4 to i64*
  %6 = getelementptr i64* %5, i64 %2
  %7 = load i64* %6, align 8
  ret i64 %7
}
@vtjnash vtjnash changed the title @inbounds does not work when applied to functions @inbounds cannot be applied to entire functions Sep 21, 2015
@fredrikekre
Copy link
Member

@StefanKarpinski
Copy link
Member

I still see the bounds checks in f as above.

@fredrikekre
Copy link
Member

Ah right, I was too quick. This part

The documentation of @inbounds suggests that it can be applied to whole functions:

is fixed, but that wasn't the issue here.

@yuyichao
Copy link
Contributor

Why is it not the issue here? This is the current expected behavior.

@StefanKarpinski
Copy link
Member

Because it would be a better for @inbounds annotations on entire functions to work? And that's what the title of the issue says that the issue is?

@Moelf
Copy link
Contributor

Moelf commented Sep 6, 2020

just re-discovered that this does not work. And our docs doesn't say explicitly it doesn't work on function definition?

both @inbounds and @fastmath can be applied to either single expressions or all the expressions that appear within nested blocks of code, e.g., using @inbounds begin or @inbounds for ....

it's hard to tell if function ... end block is an exception

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

No branches or pull requests

5 participants