Skip to content

expand memoryrefnew capabilities #58768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

oscardssmith
Copy link
Member

The goal here is 2-fold. Firstly, this should let us simplify the boundscheck (not yet implimented), but this also should reduce Julia IR side a bit.

@nsajko
Copy link
Contributor

nsajko commented Jun 18, 2025

Compiler bootstrap fails. Analyzegc says there are three errors:

https://buildkite.com/julialang/julia-master/builds/48610#019781bc-affb-431c-9bf6-49b185b59ca2/955-1695

analyzegc errors

    ANALYZE src/clang-sagc-builtins
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1780:37: error: Passing non-rooted value as argument to function that may GC [julia.GCChecker]
 1780 |                 return (jl_value_t*)jl_new_memoryref(typ, m, (char*)i);
      |                                     ^                ~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1756:5: note: Assuming 'nargs' is >= 1
 1756 |     JL_NARGS(memoryrefnew, 1, 3);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2180:9: note: expanded from macro 'JL_NARGS'
 2180 |     if (nargs < min) jl_too_few_args(#fname, min);              \
      |         ^~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1756:5: note: Taking false branch
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2180:5: note: expanded from macro 'JL_NARGS'
 2180 |     if (nargs < min) jl_too_few_args(#fname, min);              \
      |     ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1756:5: note: Assuming 'nargs' is <= 3
 1756 |     JL_NARGS(memoryrefnew, 1, 3);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2181:14: note: expanded from macro 'JL_NARGS'
 2181 |     else if (nargs > max) jl_too_many_args(#fname, max);
      |              ^~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1756:5: note: Taking false branch
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2181:10: note: expanded from macro 'JL_NARGS'
 2181 |     else if (nargs > max) jl_too_many_args(#fname, max);
      |          ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1757:9: note: Assuming 'nargs' is not equal to 1
 1757 |     if (nargs == 1) {
      |         ^~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1757:5: note: Taking false branch
 1757 |     if (nargs == 1) {
      |     ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1768:9: note: Assuming the condition is true
 1768 |         JL_TYPECHK(memoryrefnew, long, args[1]);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2187:10: note: expanded from macro 'JL_TYPECHK'
 2187 |     if (!jl_is_##type(v)) {                                        \
      |          ^~~~~~~~~~~~~~~
<scratch space>:138:1: note: expanded from here
  138 | jl_is_long
      | ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:1987:26: note: expanded from macro 'jl_is_long'
 1987 | #define jl_is_long(x)    jl_is_int64(x)
      |                          ^~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:1624:30: note: expanded from macro 'jl_is_int64'
 1624 | #define jl_is_int64(v)       jl_typetagis(v,jl_int64_tag<<4)
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:136:28: note: expanded from macro 'jl_typetagis'
  136 | #define jl_typetagis(v,t) (jl_typetagof(v)==(uintptr_t)(t))
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:118:25: note: expanded from macro 'jl_typetagof'
  118 | #define jl_typetagof(v) ((uintptr_t)_jl_typeof((jl_value_t*)(v)))
      |                         ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1768:9: note: Taking false branch
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2187:5: note: expanded from macro 'JL_TYPECHK'
 2187 |     if (!jl_is_##type(v)) {                                        \
      |     ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1769:13: note: Assuming 'nargs' is not equal to 3
 1769 |         if (nargs == 3)
      |             ^~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1769:9: note: Taking false branch
 1769 |         if (nargs == 3)
      |         ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1773:9: note: Taking true branch
 1773 |         if(jl_is_genericmemory(args[0])) {
      |         ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1775:31: note: Started tracking value here
 1775 |             jl_value_t *typ = jl_apply_type((jl_value_t*)jl_genericmemoryref_type, jl_svec_data(((jl_datatype_t*)jl_typetagof(m))->parameters), 3);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./jl_internal_funcs.inc:17:23: note: expanded from macro 'jl_apply_type'
   17 | #define jl_apply_type ijl_apply_type
      |                       ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1776:17: note: Assuming 'i' is < field 'length'
 1776 |             if (i >= m->length)
      |                 ^~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1776:13: note: Taking false branch
 1776 |             if (i >= m->length)
      |             ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1779:17: note: Assuming field 'arrayelem_isunion' is not equal to 0
 1779 |             if (layout->flags.arrayelem_isunion || layout->size == 0)
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1779:49: note: Left side of '||' is true
 1779 |             if (layout->flags.arrayelem_isunion || layout->size == 0)
      |                                                 ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1780:37: note: Passing non-rooted value as argument to function that may GC
 1780 |                 return (jl_value_t*)jl_new_memoryref(typ, m, (char*)i);
      |                                     ^                ~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1782:37: error: Passing non-rooted value as argument to function that may GC [julia.GCChecker]
 1782 |                 return (jl_value_t*)jl_new_memoryref(typ, m, (char*)m->ptr + sizeof(jl_value_t*)*i);
      |                                     ^                ~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1756:5: note: Assuming 'nargs' is >= 1
 1756 |     JL_NARGS(memoryrefnew, 1, 3);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2180:9: note: expanded from macro 'JL_NARGS'
 2180 |     if (nargs < min) jl_too_few_args(#fname, min);              \
      |         ^~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1756:5: note: Taking false branch
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2180:5: note: expanded from macro 'JL_NARGS'
 2180 |     if (nargs < min) jl_too_few_args(#fname, min);              \
      |     ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1756:5: note: Assuming 'nargs' is <= 3
 1756 |     JL_NARGS(memoryrefnew, 1, 3);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2181:14: note: expanded from macro 'JL_NARGS'
 2181 |     else if (nargs > max) jl_too_many_args(#fname, max);
      |              ^~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1756:5: note: Taking false branch
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2181:10: note: expanded from macro 'JL_NARGS'
 2181 |     else if (nargs > max) jl_too_many_args(#fname, max);
      |          ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1757:9: note: Assuming 'nargs' is not equal to 1
 1757 |     if (nargs == 1) {
      |         ^~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1757:5: note: Taking false branch
 1757 |     if (nargs == 1) {
      |     ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1768:9: note: Assuming the condition is true
 1768 |         JL_TYPECHK(memoryrefnew, long, args[1]);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2187:10: note: expanded from macro 'JL_TYPECHK'
 2187 |     if (!jl_is_##type(v)) {                                        \
      |          ^~~~~~~~~~~~~~~
<scratch space>:138:1: note: expanded from here
  138 | jl_is_long
      | ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:1987:26: note: expanded from macro 'jl_is_long'
 1987 | #define jl_is_long(x)    jl_is_int64(x)
      |                          ^~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:1624:30: note: expanded from macro 'jl_is_int64'
 1624 | #define jl_is_int64(v)       jl_typetagis(v,jl_int64_tag<<4)
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:136:28: note: expanded from macro 'jl_typetagis'
  136 | #define jl_typetagis(v,t) (jl_typetagof(v)==(uintptr_t)(t))
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:118:25: note: expanded from macro 'jl_typetagof'
  118 | #define jl_typetagof(v) ((uintptr_t)_jl_typeof((jl_value_t*)(v)))
      |                         ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1768:9: note: Taking false branch
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2187:5: note: expanded from macro 'JL_TYPECHK'
 2187 |     if (!jl_is_##type(v)) {                                        \
      |     ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1769:13: note: Assuming 'nargs' is not equal to 3
 1769 |         if (nargs == 3)
      |             ^~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1769:9: note: Taking false branch
 1769 |         if (nargs == 3)
      |         ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1773:9: note: Taking true branch
 1773 |         if(jl_is_genericmemory(args[0])) {
      |         ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1775:31: note: Started tracking value here
 1775 |             jl_value_t *typ = jl_apply_type((jl_value_t*)jl_genericmemoryref_type, jl_svec_data(((jl_datatype_t*)jl_typetagof(m))->parameters), 3);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./jl_internal_funcs.inc:17:23: note: expanded from macro 'jl_apply_type'
   17 | #define jl_apply_type ijl_apply_type
      |                       ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1776:17: note: Assuming 'i' is < field 'length'
 1776 |             if (i >= m->length)
      |                 ^~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1776:13: note: Taking false branch
 1776 |             if (i >= m->length)
      |             ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1779:17: note: Assuming field 'arrayelem_isunion' is 0
 1779 |             if (layout->flags.arrayelem_isunion || layout->size == 0)
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1779:17: note: Left side of '||' is false
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1779:52: note: Assuming field 'size' is not equal to 0
 1779 |             if (layout->flags.arrayelem_isunion || layout->size == 0)
      |                                                    ^~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1779:13: note: Taking false branch
 1779 |             if (layout->flags.arrayelem_isunion || layout->size == 0)
      |             ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1781:22: note: Assuming field 'arrayelem_isboxed' is not equal to 0
 1781 |             else if (layout->flags.arrayelem_isboxed)
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1781:18: note: Taking true branch
 1781 |             else if (layout->flags.arrayelem_isboxed)
      |                  ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1782:37: note: Passing non-rooted value as argument to function that may GC
 1782 |                 return (jl_value_t*)jl_new_memoryref(typ, m, (char*)m->ptr + sizeof(jl_value_t*)*i);
      |                                     ^                ~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1783:33: error: Passing non-rooted value as argument to function that may GC [julia.GCChecker]
 1783 |             return (jl_value_t*)jl_new_memoryref(typ, m, (char*)m->ptr + layout->size*i);
      |                                 ^                ~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1756:5: note: Assuming 'nargs' is >= 1
 1756 |     JL_NARGS(memoryrefnew, 1, 3);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2180:9: note: expanded from macro 'JL_NARGS'
 2180 |     if (nargs < min) jl_too_few_args(#fname, min);              \
      |         ^~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1756:5: note: Taking false branch
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2180:5: note: expanded from macro 'JL_NARGS'
 2180 |     if (nargs < min) jl_too_few_args(#fname, min);              \
      |     ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1756:5: note: Assuming 'nargs' is <= 3
 1756 |     JL_NARGS(memoryrefnew, 1, 3);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2181:14: note: expanded from macro 'JL_NARGS'
 2181 |     else if (nargs > max) jl_too_many_args(#fname, max);
      |              ^~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1756:5: note: Taking false branch
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2181:10: note: expanded from macro 'JL_NARGS'
 2181 |     else if (nargs > max) jl_too_many_args(#fname, max);
      |          ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1757:9: note: Assuming 'nargs' is not equal to 1
 1757 |     if (nargs == 1) {
      |         ^~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1757:5: note: Taking false branch
 1757 |     if (nargs == 1) {
      |     ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1768:9: note: Assuming the condition is true
 1768 |         JL_TYPECHK(memoryrefnew, long, args[1]);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2187:10: note: expanded from macro 'JL_TYPECHK'
 2187 |     if (!jl_is_##type(v)) {                                        \
      |          ^~~~~~~~~~~~~~~
<scratch space>:138:1: note: expanded from here
  138 | jl_is_long
      | ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:1987:26: note: expanded from macro 'jl_is_long'
 1987 | #define jl_is_long(x)    jl_is_int64(x)
      |                          ^~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:1624:30: note: expanded from macro 'jl_is_int64'
 1624 | #define jl_is_int64(v)       jl_typetagis(v,jl_int64_tag<<4)
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:136:28: note: expanded from macro 'jl_typetagis'
  136 | #define jl_typetagis(v,t) (jl_typetagof(v)==(uintptr_t)(t))
      |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:118:25: note: expanded from macro 'jl_typetagof'
  118 | #define jl_typetagof(v) ((uintptr_t)_jl_typeof((jl_value_t*)(v)))
      |                         ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1768:9: note: Taking false branch
/cache/build/builder-amdci4-2/julialang/julia-master/src/julia.h:2187:5: note: expanded from macro 'JL_TYPECHK'
 2187 |     if (!jl_is_##type(v)) {                                        \
      |     ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1769:13: note: Assuming 'nargs' is not equal to 3
 1769 |         if (nargs == 3)
      |             ^~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1769:9: note: Taking false branch
 1769 |         if (nargs == 3)
      |         ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1773:9: note: Taking true branch
 1773 |         if(jl_is_genericmemory(args[0])) {
      |         ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1775:31: note: Started tracking value here
 1775 |             jl_value_t *typ = jl_apply_type((jl_value_t*)jl_genericmemoryref_type, jl_svec_data(((jl_datatype_t*)jl_typetagof(m))->parameters), 3);
      |                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./jl_internal_funcs.inc:17:23: note: expanded from macro 'jl_apply_type'
   17 | #define jl_apply_type ijl_apply_type
      |                       ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1776:17: note: Assuming 'i' is < field 'length'
 1776 |             if (i >= m->length)
      |                 ^~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1776:13: note: Taking false branch
 1776 |             if (i >= m->length)
      |             ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1779:17: note: Assuming field 'arrayelem_isunion' is 0
 1779 |             if (layout->flags.arrayelem_isunion || layout->size == 0)
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1779:17: note: Left side of '||' is false
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1779:52: note: Assuming field 'size' is not equal to 0
 1779 |             if (layout->flags.arrayelem_isunion || layout->size == 0)
      |                                                    ^~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1779:13: note: Taking false branch
 1779 |             if (layout->flags.arrayelem_isunion || layout->size == 0)
      |             ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1781:22: note: Assuming field 'arrayelem_isboxed' is 0
 1781 |             else if (layout->flags.arrayelem_isboxed)
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1781:18: note: Taking false branch
 1781 |             else if (layout->flags.arrayelem_isboxed)
      |                  ^
/cache/build/builder-amdci4-2/julialang/julia-master/src/builtins.c:1783:33: note: Passing non-rooted value as argument to function that may GC
 1783 |             return (jl_value_t*)jl_new_memoryref(typ, m, (char*)m->ptr + layout->size*i);
      |                                 ^                ~~~
3 errors generated.
make: *** [Makefile:558: clang-sagc-builtins] Error 1

@oscardssmith
Copy link
Member Author

analyzegc issue was pretty simple.

@oscardssmith oscardssmith force-pushed the os/more-memoryrefnew branch from f51b1ea to 19e1d93 Compare June 19, 2025 00:28
@@ -720,7 +720,9 @@ function iscall_with_boundscheck(@nospecialize(stmt), sv::PostOptAnalysisState)
f === nothing && return false
if f === getfield
nargs = 4
elseif f === memoryrefnew || f === memoryrefget || f === memoryref_isassigned
elseif f === memoryrefnew
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a fun bugfix...

@giordano
Copy link
Member

Now there's only one failing test

Error in testset REPL:
Test Failed at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/julia-e1f2398ab5/share/julia/stdlib/v1.13/REPL/test/precompilation.jl:40
  Expression: n_precompiles <= expected_precompiles
   Evaluated: 2 <= 0

@oscardssmith
Copy link
Member Author

yeah. that said, before I fix that, it's probably time to actually add the different simplification that was the main point of this pr

@oscardssmith
Copy link
Member Author

oscardssmith commented Jun 20, 2025

Codegen added! (thanks @gbaraldi), code looks a lot better now. for

julia> ms = Memory{Int}(undef, 5)
julia> @code_native debuginfo=:none m2[3]

we now get

	.file	"getindex"
	.section	.ltext,"axl",@progbits
	.globl	julia_getindex_1350             # -- Begin function julia_getindex_1350
	.p2align	4
	.type	julia_getindex_1350,@function
julia_getindex_1350:                    # @julia_getindex_1350
; Function Signature: getindex(Memory{Int64}, Int64)
# %bb.0:                                # %top
	#DEBUG_VALUE: getindex:A <- [$rdi+0]
	#DEBUG_VALUE: getindex:i <- $rsi
	lea	rax, [rsi - 1]
	cmp	rax, qword ptr [rdi]
	jae	.LBB0_2
# %bb.1:                                # %L14
	mov	rax, qword ptr [rdi + 8]
	mov	rax, qword ptr [rax + 8*rsi - 8]
	ret
.LBB0_2:                                # %L10
	push	rbp
	mov	rbp, rsp
	sub	rsp, 16
	mov	qword ptr [rbp - 8], rsi
	movabs	rax, offset j_throw_boundserror_1352
	lea	rsi, [rbp - 8]
	call	rax
.Lfunc_end0:

while before it was

	.text
	.file	"getindex"
	.section	.ltext,"axl",@progbits
	.globl	julia_getindex_1455             # -- Begin function julia_getindex_1455
	.p2align	4, 0x90
	.type	julia_getindex_1455,@function
julia_getindex_1455:                    # @julia_getindex_1455
; Function Signature: getindex(Memory{Int64}, Int64)
# %bb.0:                                # %top
	#DEBUG_VALUE: getindex:A <- [$rdi+0]
	#DEBUG_VALUE: getindex:i <- $rsi
	push	rbp
	mov	rbp, rsp
	push	r15
	push	r14
	push	r12
	push	rbx
	mov	rax, qword ptr [rdi]
	mov	r15, qword ptr [rdi + 8]
	lea	rdx, [rax + rsi - 1]
	lea	rcx, [rax + rax]
	cmp	rdx, rcx
	jae	.LBB0_3
# %bb.1:                                # %top
	lea	rcx, [8*rsi - 8]
	shl	rax, 3
	cmp	rcx, rax
	jae	.LBB0_3
# %bb.2:                                # %idxend
	mov	rax, qword ptr [r15 + 8*rsi - 8]
	pop	rbx
	pop	r12
	pop	r14
	pop	r15
	pop	rbp
	ret
.LBB0_3:                                # %oob
	#APP
	mov	rax, qword ptr fs:[0]
	#NO_APP
	mov	rax, qword ptr [rax - 8]
	movabs	rbx, 138975374889648
	mov	r14, rsi
	movabs	r8, offset ijl_gc_small_alloc
	mov	esi, 408
	mov	edx, 32
	mov	r12, rdi
	mov	rcx, rbx
	mov	rax, qword ptr [rax + 16]
	mov	rdi, rax
	call	r8
	movabs	rcx, offset ijl_bounds_error_int
	mov	qword ptr [rax - 8], rbx
	mov	qword ptr [rax], r15
	mov	qword ptr [rax + 8], r12
	mov	rdi, rax
	mov	rsi, r14
	call	rcx
.Lfunc_end0:

@oscardssmith
Copy link
Member Author

@nanosoldier runbenchmarks(!"scalar" vs=":master")

@oscardssmith
Copy link
Member Author

@nanosoldier runbenchmarks(!"scalar", vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

@oscardssmith oscardssmith force-pushed the os/more-memoryrefnew branch from d4b610d to 0b6f8d4 Compare June 24, 2025 13:51
const jl_datatype_layout_t *layout = ((jl_datatype_t*)jl_typetagof(m->mem))->layout;
char *data = (char*)m->ptr_or_offset;
char *data;
if(jl_is_genericmemory(args[0])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(jl_is_genericmemory(args[0])) {
if (jl_is_genericmemory(args[0])) {

@oscardssmith
Copy link
Member Author

nanosoldier regressions do not reproduce locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants