Skip to content

JIT: Missing sign extension for bswap16 #67723

Closed
@jakobbotsch

Description

@jakobbotsch

Description

The following program gives a wrong result when optimizing:

Reproduction Steps

// Debug: 80
// Release: ffff0080
using System.Buffers.Binary;

short[] foo = { short.MinValue };
int test = BinaryPrimitives.ReverseEndianness(foo[0]);
System.Console.WriteLine(test.ToString("x"));

Expected behavior

Same result.

Actual behavior

Different results.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

We do insert the cast when we import. Looks like value numbering ends up assigning the same liberal VN to the cast and the bswap16 and CSE then effectively removes the sign extension.

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions