Bug 21833 – Optimizer incorrectly rewrites integer comparison to unsigned short comparison

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-04-16T10:06:25Z
Last change time
2021-04-19T02:36:06Z
Keywords
backend, pull, wrong-code
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2021-04-16T10:06:25Z
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() { testit(); }
Comment #1 by dlang-bot — 2021-04-16T10:12:05Z
@WalterBright created dlang/dmd pull request #12444 "fix Issue 21833 - Optimizer incorrectly rewrites integer comparison t…" fixing this issue: - fix Issue 21833 - Optimizer incorrectly rewrites integer comparison to unsigned short comparison https://github.com/dlang/dmd/pull/12444
Comment #2 by dlang-bot — 2021-04-19T02:36:06Z
dlang/dmd pull request #12444 "fix Issue 21833 - Optimizer incorrectly rewrites integer comparison t…" was merged into master: - 4adcfb79a21b01021589f99900e973fac1100820 by Walter Bright: fix Issue 21833 - Optimizer incorrectly rewrites integer comparison to unsigned short comparison https://github.com/dlang/dmd/pull/12444