Issue Details (XML | Word | Printable)

Key: BOO-1112
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Cedric Vivier
Reporter: Cedric Vivier
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Boo

Inefficient IL for unary negations (especially negative floating-point literals)

Created: 15/Jan/09 11:59 AM   Updated: 15/Jan/09 02:06 PM   Resolved: 15/Jan/09 02:06 PM
Return to search
Component/s: Compiler
Affects Version/s: 0.8.2
Fix Version/s: 0.9

Time Tracking:
Not Specified


 Description  « Hide

x as double = -1.0

Generates this:

ldc.r8 1.
ldc.i4 -1
conv.r8 
mul 
stloc.0

Instead of:

ldc.r8 -1.
stloc.0

x = -x (with x an int)

Generates this:

ldloc.0
ldc.i4 -1
mul 
stloc.0

Instead of:

ldc.i4.0
ldloc.0
sub.ovf
stloc.0

Or even (for unchecked blocks and any single/double):

ldloc.0
neg
stloc.0


Cedric Vivier made changes - 15/Jan/09 12:00 PM
Field Original Value New Value
Description x as double = -1.0

Generates this:
{code}
IL_0000: ldc.r8 1.
IL_0009: ldc.i4 -1
IL_000e: conv.r8
IL_000f: mul
IL_0010: conv.r4
IL_0011: stloc.0
{code}

Instead of:
{code}
ldc.r8 -1.
stloc.0
{code}
x as double = -1.0

Generates this:
{code}
ldc.r8 1.
ldc.i4 -1
conv.r8
mul
stloc.0
{code}

Instead of:
{code}
ldc.r8 -1.
stloc.0
{code}
Cedric Vivier made changes - 15/Jan/09 01:39 PM
Description x as double = -1.0

Generates this:
{code}
ldc.r8 1.
ldc.i4 -1
conv.r8
mul
stloc.0
{code}

Instead of:
{code}
ldc.r8 -1.
stloc.0
{code}
x as double = -1.0

Generates this:
{code}
ldc.r8 1.
ldc.i4 -1
conv.r8
mul
stloc.0
{code}

Instead of:
{code}
ldc.r8 -1.
stloc.0
{code}



x = -x (with x an int)

Generates this:
{code}
ldloc.0
ldc.i4 -1
mul
stloc.0
{code}

Instead of:
{code}
ldc.i4.0
ldloc.0
sub.ovf
stloc.0
{code}


Or even (for unchecked blocks and any single/double):
{code}
ldloc.0
neg
stloc.0
{code}
Summary Very innefficient IL for negative floating-point literals Inefficient IL for unary negations (especially negative floating-point literals)
Cedric Vivier added a comment - 15/Jan/09 02:06 PM

Fixed in rev. 3103


Cedric Vivier made changes - 15/Jan/09 02:06 PM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]