@@ -1296,14 +1296,14 @@ function memory_opt!(ir::IRCode)
12961296
12971297 # TODO : Replace this by interprocedural escape analysis
12981298 if is_known_call (stmt, arrayset, compact)
1299- # arrayset expr.args:
1299+ # arrayset expr.args:
13001300 # :(Base.arrayset)
1301- # false
1301+ # false
13021302 # :(%2) array
1303- # :(%8) value
1303+ # :(%8) value
13041304 # :(%7) index
13051305 # The value being set escapes, everything else doesn't
1306- (length (stmt. args) == 5 ) || continue # fix boundserror during precompile --- but how do we have arrayset with < 5 args?
1306+ (length (stmt. args) == 5 ) || continue # fix boundserror during precompile --- but how do we have arrayset with < 5 args?
13071307 mark_escape (stmt. args[4 ])
13081308 arr = stmt. args[3 ]
13091309 if isa (arr, SSAValue) && arr. id in relevant
@@ -1314,18 +1314,27 @@ function memory_opt!(ir::IRCode)
13141314 elseif is_known_call (stmt, Core. arrayfreeze, compact) && isa (stmt. args[2 ], SSAValue)
13151315 push! (revisit, idx)
13161316
1317- elseif is_known_call (stmt, arraysize, compact) && isa (stmt. args[2 ], SSAValue)
1317+ elseif is_known_call (stmt, arraysize, compact) && isa (stmt. args[2 ], SSAValue) && isa (stmt . args[ 3 ], Number)
13181318 arr = stmt. args[2 ]
1319- typ = abstract_eval_ssavalue (arr, compact)
1319+ dim = stmt. args[3 ]
1320+ typ = types (compact)[arr]
13201321
1321- # make sure this call isn't going to throw
1322- if typ != Union{} && typ <: AbstractArray && ndims (typ) == stmt. args[3 ]
1322+ while ! isa (typ, Type)
1323+ typ = typeof (typ)
1324+ end
1325+
1326+ if isa (typ, Core. Const)
1327+ typ = typ. val
1328+ end
1329+
1330+ # make sure this call isn't going to throw
1331+ if typ <: AbstractArray && dim >= 1
13231332 # don't escape the array, but mark usage for dom analysis
13241333 if arr. id in relevant
13251334 (haskey (uses, arr. id)) || (uses[arr. id] = Int[])
13261335 push! (uses[arr. id], idx)
13271336 end
1328- else # if this call throws, the array definitely escapes
1337+ else # if this call throws or we can't tell , the array definitely escapes
13291338 for ur in userefs (stmt)
13301339 mark_escape (ur[])
13311340 end
0 commit comments