diff --git a/test/abstractarray.jl b/test/abstractarray.jl index df2dbe1c198b9..bc8474583a6e6 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -1571,8 +1571,15 @@ end @test reshape(r, :) === reshape(r, (:,)) === r end +module IRUtils + include(normpath(@__DIR__, "./compiler/irutils.jl")) +end + @testset "strides for ReshapedArray" begin - # Type-based contiguous check is tested in test/compiler/inline.jl + # Type-based contiguous Check + a = vec(reinterpret(reshape,Int16,reshape(view(reinterpret(Int32,randn(10)),2:11),5,:))) + f(a) = only(strides(a)); + @test IRUtils.fully_eliminated(f, Base.typesof(a)) && f(a) == 1 # General contiguous check a = view(rand(10,10), 1:10, 1:10) @test strides(vec(a)) == (1,) @@ -1610,3 +1617,21 @@ end i = CartesianIndex((1,1)) @test (@inferred A[i,i,i]) === A[1] end + +@testset "type-based offset axes check" begin + a = randn(ComplexF64, 10) + ta = reinterpret(Float64, a) + tb = reinterpret(Float64, view(a, 1:2:10)) + tc = reinterpret(Float64, reshape(view(a, 1:3:10), 2, 2, 1)) + # Issue #44040 + @test IRUtils.fully_eliminated(Base.require_one_based_indexing, Base.typesof(ta,tc)) + @test IRUtils.fully_eliminated(Base.require_one_based_indexing, Base.typesof(tc,tc)) + @test IRUtils.fully_eliminated(Base.require_one_based_indexing, Base.typesof(ta,tc,tb)) + # Ranges && CartesianIndices + @test IRUtils.fully_eliminated(Base.require_one_based_indexing, Base.typesof(1:10,Base.OneTo(10),1.0:2.0,LinRange(1.0,2.0,2),1:2:10,CartesianIndices((1:2:10,1:2:10)))) + # Remind us to call `any` in `Base.has_offset_axes` once our compiler is ready. + @inline _has_offset_axes(A) = @inline any(x->Int(first(x))::Int != 1, axes(A)) + @inline _has_offset_axes(As...) = @inline any(_has_offset_axes, As) + a, b = zeros(2,2,2), zeros(2,2) + @test_broken IRUtils.fully_eliminated(_has_offset_axes, Base.typesof(a,a,b,b)) +end diff --git a/test/compiler/inline.jl b/test/compiler/inline.jl index 9ad5a9265c341..06e87ecb25c67 100644 --- a/test/compiler/inline.jl +++ b/test/compiler/inline.jl @@ -995,13 +995,6 @@ end Base.@invoke conditional_escape!(false::Any, x::Any) end -@testset "strides for ReshapedArray (PR#44027)" begin - # Type-based contiguous check - a = vec(reinterpret(reshape,Int16,reshape(view(reinterpret(Int32,randn(10)),2:11),5,:))) - f(a) = only(strides(a)); - @test fully_eliminated(f, Tuple{typeof(a)}) && f(a) == 1 -end - @testset "elimination of `get_binding_type`" begin m = Module() @eval m begin @@ -1259,21 +1252,3 @@ end @test fully_eliminated() do return maybe_error_int(1) end - -@testset "type-based offset axes check" begin - a = randn(ComplexF64, 10) - ta = reinterpret(Float64, a) - tb = reinterpret(Float64, view(a, 1:2:10)) - tc = reinterpret(Float64, reshape(view(a, 1:3:10), 2, 2, 1)) - # Issue #44040 - @test fully_eliminated(Base.require_one_based_indexing, Base.typesof(ta,tc)) - @test fully_eliminated(Base.require_one_based_indexing, Base.typesof(tc,tc)) - @test fully_eliminated(Base.require_one_based_indexing, Base.typesof(ta,tc,tb)) - # Ranges && CartesianIndices - @test fully_eliminated(Base.require_one_based_indexing, Base.typesof(1:10,Base.OneTo(10),1.0:2.0,LinRange(1.0,2.0,2),1:2:10,CartesianIndices((1:2:10,1:2:10)))) - # Remind us to call `any` in `Base.has_offset_axes` once our compiler is ready. - @inline _has_offset_axes(A) = @inline any(x->Int(first(x))::Int != 1, axes(A)) - @inline _has_offset_axes(As...) = @inline any(_has_offset_axes, As) - a, b = zeros(2,2,2), zeros(2,2) - @test_broken fully_eliminated(_has_offset_axes, Base.typesof(a,a,b,b)) -end