www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 21833] New: Optimizer incorrectly rewrites integer operation


          Issue ID: 21833
           Summary: Optimizer incorrectly rewrites integer operation to
                    short operation
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: bugzilla digitalmars.com

The code:

void testit()
    pragma(inline, false);
    short[4] arr = [-1, 6, 0, 4];
    long1 A = *cast(long1*)(arr.ptr);
    assert(_mm_extract_pi16(A, 0) == 65535); // Error here

struct short4
    short[4] array;

struct long1
    long[1] array;

int _mm_extract_pi16 (long1 a, int imm8)
    return cast(ushort)((cast(short4)a).array[imm8]);

The error is the optimizer incorrectly rewrites 65535 to be an unsigned short
and then does a signed short comparison, which fails to match the left hand
side which is a short. Should rewrite it as a short.
void main()

Apr 16 2021