Skip to content

uint64 literals generate suboptimal IL code #8683

@teo-tsirpanis

Description

@teo-tsirpanis

Repro steps

Consider this function:

let inc x = x + 1UL

Now look at the generated IL code:

Expected behavior

IL_0000: ldarg.0
IL_0001: ldc.i4.1
IL_0002: conv.u8
IL_0003: add
IL_0004: ret

This is what C# generates. Generally, it should emit ldc.i4.#/ldc.i4.s/ldc.i4 with a conv, and only if the number is even bigger should it emit ldc.i8.

Actual behavior

IL_0000: ldarg.0
IL_0001: ldc.i8 1
IL_000a: add
IL_000b: ret

The function's IL code takes 12 bytes, instead of 5, as expected. This might interfere with the JIT's decision to inline small functions.

Known workarounds

let inc x = x + (uint64 1)

Related information

This happens only with uint64 literals. Literals of all other integral types (including signed int64) emit optimal code.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions