From ded74ba4229c5bdb286057204aa50a8c8895f472 Mon Sep 17 00:00:00 2001 From: chriselrod Date: Wed, 5 Apr 2023 16:05:48 -0400 Subject: [PATCH] Fix a problem in #483 --- Project.toml | 2 +- src/codegen/lower_threads.jl | 8 +++++++- test/threading.jl | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 89b61b26c..c648f477a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "LoopVectorization" uuid = "bdcacae8-1622-11e9-2a5c-532679323890" authors = ["Chris Elrod "] -version = "0.12.155" +version = "0.12.156" [weakdeps] ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" diff --git a/src/codegen/lower_threads.jl b/src/codegen/lower_threads.jl index c3ec229df..6c268a30d 100644 --- a/src/codegen/lower_threads.jl +++ b/src/codegen/lower_threads.jl @@ -196,7 +196,13 @@ function push_loop_length_expr!(q::Expr, ls::LoopSet) if length(ls.loops) == 1 ndynamic == 0 && push!(q.args, l) elseif l == 1 - push!(q.args, mulexpr) + if ndynamic == 1 + push!(q.args, last(mulexpr.args)) + elseif ndynamic == 0 + push!(q.args, l) + else + push!(q.args, mulexpr) + end elseif ndynamic == 0 push!(q.args, l) elseif ndynamic == 1 diff --git a/test/threading.jl b/test/threading.jl index 1f9ed8dfc..5620f8346 100644 --- a/test/threading.jl +++ b/test/threading.jl @@ -172,4 +172,13 @@ end thread_cartesian_indices!(dst, src) dst ≈ src + let a = zeros(3, 2), N = 2 + @turbo thread = true for i = 1:1, j = 1:N + a[i, j] += 1.0 + end + @test all(isone, @view(a[1, :])) + @test all(iszero, @view(a[2:end, :])) + end + + end