Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Sep 17, 2019

static int Test() => "Hello".Length; // replace with just `5`

Before:

movabs rax,0x7fd6c1758160
mov    eax,DWORD PTR [rax]
ret 

Now:

mov    eax,0x5
ret

Also, handles cases after inlining, e.g.:

bool Validate(string str)
{
    return str.Length > 0 && str.Length <= 100;
}

bool Test()
{
    return Validate("Hello");  // Validate() will be inlined
}

New codegen for Test:

mov    eax, 1     ; return true
ret  

I have a similar PR for CoreCLR: dotnet/runtime#1378
jit-diff report found >30k bytes of improvements.

@kg
Copy link
Member

kg commented Sep 17, 2019

@monojenkins build failed

@akoeplinger
Copy link
Member

/azp run sync-mono-to-runtime

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

MONO_EMIT_NEW_LOAD_MEMBASE_OP_FLAGS (cfg, OP_LOADI4_MEMBASE, ins->dreg,
ins->sreg1, MONO_STRUCT_OFFSET (MonoString, length), ins->flags | MONO_INST_INVARIANT_LOAD);
if (ins->prev && ins->prev->opcode == OP_I8CONST) {
// Optimize String.get_length for ldstr, e.g.:
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to check that ins->prev->dreg == ins->sreg1.

// Optimize String.get_length for ldstr, e.g.:
// "hello".Length => 5
mono_domain_lock(cfg->domain);
MonoGHashTable* table = cfg->domain->ldstr_table;
Copy link
Contributor

Choose a reason for hiding this comment

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

Coding style.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants