X86-64: SHRD r32 incorrectly handles shift counts exceeding 31

Given the following minimal example:

repro:
    xor ecx, ecx
    mov r8, 1122334466666BADh
    shrd r8d, r8d, 33
    mov rax, r8
    ret

At MMAT_GENERATED, the SHRD instruction is lowered into:

mov    r8d.4, et0.4 ; u=r8d.4      d=et0.4
mov    r8d.4, rt0^4.4 ; u=r8d.4      d=rt0^4.4
mov    #0x21.1, t2.1 ; u=           d=t2.1
shr    rt0.8, t2.1, rt0.8 ; u=rt0.8,t2.1 d=rt0.8
mov    et0.4, r8d.4 ; u=et0.4      d=r8d.4
xdu    r8d.4, r8.8 ; u=r8d.4      d=r8^4.4

Notice that the shift uses the original count of 0x21 (33).

At MMAT_LVARS:

mov    #0x333335D6.8, result.8 ; u=           d=rax.8

Resulting in:

return 0x333335D6;

For a 32-bit SHRD, the count is masked to five bits, so a count of 33 is equivalent to a count of one.

Since both operands are r8d, the operation is equivalent to a 32-bit rotate-right by one bit. The expected result is therefore:

return 0xB33335D6;

The corresponding test using an immediate count of one is decompiled correctly, so this appears specific to handling counts that require masking.

Hi, just a quick heads-up: we’ve logged this issue along with your other x86-64 reports.

Thanks as always for the quick replies! Hopefully you guys don’t mind this method of submission. Let me know if you’d prefer a different approach in the future, or if related issues like the SHRD reports would be better combined. This is just how I would’ve organized them in an internal issue tracker, so it felt reasonable.

Separate topics work for us, thanks! We’ll link them in our internal tracker if needed.

For future bug reports, you can also use our support channel. Responses there are usually faster, and it’s easier to follow up with you directly.

Doesn’t support channel require purchased license for login? For example I use the IDA Free and yet want to report bugs. Maybe either democratize support channel or I don’t know, quite inconvenient to open threads for small bugs on community forum. Thanks.

I use IDA Free and I’ve report various bugs (INTERR, PDB, GUI issues) to the support@ email and the new method on the website.