@@ -1571,8 +1571,15 @@ end
15711571 @test reshape (r, :) === reshape (r, (:,)) === r
15721572end
15731573
1574+ module IRUtils
1575+ include (normpath (@__DIR__ , " ./compiler/irutils.jl" ))
1576+ end
1577+
15741578@testset " strides for ReshapedArray" begin
1575- # Type-based contiguous check is tested in test/compiler/inline.jl
1579+ # Type-based contiguous Check
1580+ a = vec (reinterpret (reshape,Int16,reshape (view (reinterpret (Int32,randn (10 )),2 : 11 ),5 ,:)))
1581+ f (a) = only (strides (a));
1582+ @test IRUtils. fully_eliminated (f, Base. typesof (a)) && f (a) == 1
15761583 # General contiguous check
15771584 a = view (rand (10 ,10 ), 1 : 10 , 1 : 10 )
15781585 @test strides (vec (a)) == (1 ,)
@@ -1610,3 +1617,21 @@ end
16101617 i = CartesianIndex ((1 ,1 ))
16111618 @test (@inferred A[i,i,i]) === A[1 ]
16121619end
1620+
1621+ @testset " type-based offset axes check" begin
1622+ a = randn (ComplexF64, 10 )
1623+ ta = reinterpret (Float64, a)
1624+ tb = reinterpret (Float64, view (a, 1 : 2 : 10 ))
1625+ tc = reinterpret (Float64, reshape (view (a, 1 : 3 : 10 ), 2 , 2 , 1 ))
1626+ # Issue #44040
1627+ @test IRUtils. fully_eliminated (Base. require_one_based_indexing, Base. typesof (ta,tc))
1628+ @test IRUtils. fully_eliminated (Base. require_one_based_indexing, Base. typesof (tc,tc))
1629+ @test IRUtils. fully_eliminated (Base. require_one_based_indexing, Base. typesof (ta,tc,tb))
1630+ # Ranges && CartesianIndices
1631+ @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 ))))
1632+ # Remind us to call `any` in `Base.has_offset_axes` once our compiler is ready.
1633+ @inline _has_offset_axes (A) = @inline any (x-> Int (first (x)):: Int != 1 , axes (A))
1634+ @inline _has_offset_axes (As... ) = @inline any (_has_offset_axes, As)
1635+ a, b = zeros (2 ,2 ,2 ), zeros (2 ,2 )
1636+ @test_broken IRUtils. fully_eliminated (_has_offset_axes, Base. typesof (a,a,b,b))
1637+ end
0 commit comments