@@ -87,10 +87,14 @@ function transform_gpu!(def, constargs, force_inbounds, unsafe_indices)
8787 push! (let_constargs, :($ arg = $ constify ($ arg)))
8888 end
8989 end
90+ has_constargs = ! isempty (let_constargs)
9091 pushfirst! (def[:args ], :__ctx__ )
9192 new_stmts = Expr[]
9293 body = MacroTools. flatten (def[:body ])
93- push! (new_stmts, Expr (:aliasscope ))
94+ # On 1.11 and later having this aliasscope causes issues
95+ # even with kernels that don't use `@Const` on arguments
96+ # See https://github.com/JuliaGPU/KernelAbstractions.jl/issues/652
97+ has_constargs && push! (new_stmts, Expr (:aliasscope ))
9498 if ! unsafe_indices
9599 push! (new_stmts, :(__active_lane__ = $ __validindex (__ctx__)))
96100 end
@@ -105,7 +109,7 @@ function transform_gpu!(def, constargs, force_inbounds, unsafe_indices)
105109 if force_inbounds
106110 push! (new_stmts, Expr (:inbounds , :pop ))
107111 end
108- push! (new_stmts, Expr (:popaliasscope ))
112+ has_constargs && push! (new_stmts, Expr (:popaliasscope ))
109113 push! (new_stmts, :(return nothing ))
110114 def[:body ] = Expr (
111115 :let ,
@@ -129,18 +133,22 @@ function transform_cpu!(def, constargs, force_inbounds)
129133 push! (let_constargs, :($ arg = $ constify ($ arg)))
130134 end
131135 end
136+ has_constargs = ! isempty (let_constargs)
132137 pushfirst! (def[:args ], :__ctx__ )
133138 new_stmts = Expr[]
134139 body = MacroTools. flatten (def[:body ])
135- push! (new_stmts, Expr (:aliasscope ))
140+ # On 1.11 and later having this aliasscope causes issues
141+ # even with kernels that don't use `@Const` on arguments
142+ # See https://github.com/JuliaGPU/KernelAbstractions.jl/issues/652
143+ has_constargs && push! (new_stmts, Expr (:aliasscope ))
136144 if force_inbounds
137145 push! (new_stmts, Expr (:inbounds , true ))
138146 end
139147 append! (new_stmts, split (emit_cpu, body. args))
140148 if force_inbounds
141149 push! (new_stmts, Expr (:inbounds , :pop ))
142150 end
143- push! (new_stmts, Expr (:popaliasscope ))
151+ has_constargs && push! (new_stmts, Expr (:popaliasscope ))
144152 push! (new_stmts, :(return nothing ))
145153 def[:body ] = Expr (
146154 :let ,
0 commit comments