# X86-64: SHRD/SHLD omit defined flag updates

**URL:** <https://community.hex-rays.com/t/x86-64-shrd-shld-omit-defined-flag-updates/861>\
**Category:** Bugs\
**Created:** [November 2, 2026, 10:55pm UTC](https://community.hex-rays.com/t/x86-64-shrd-shld-omit-defined-flag-updates/861 "2026-11-02T22:55:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![QuietMaple10](https://avatars.discourse-cdn.com/v4/letter/q/50afbb/32.png) [@QuietMaple10](https://community.hex-rays.com/u/QuietMaple10)\
**Post date:** [November 2, 2026, 10:55pm UTC](https://community.hex-rays.com/t/x86-64-shrd-shld-omit-defined-flag-updates/861/1 "2026-11-02T22:55:16Z")

</div>

Given these two minimal examples:

```x86asm
shrd_of:
    xor ecx, ecx
    mov eax, 0DEADh
    mov edx, 0BEEFh
    mov r8, 0DEADh
    shrd r8, r8, 1
    cmovo rax, rdx
    ret

shld_of:
    xor ecx, ecx
    mov eax, 0DEADh
    mov edx, 0BEEFh
    mov r8, 8000000000000001h
    shld r8, r8, 1
    cmovo rax, rdx
    ret

```

At `MMAT_GENERATED`, the `SHRD` instruction is lowered into register operations without updating any of the affected flags:

```plaintext
mov r8.8, rt0.8 ; u=r8.8 d=rt0.8
mov r8.8, rt0^8.8 ; u=r8.8 d=rt0^8.8
mov #1.1, t2.1 ; u= d=t2.1
or (rt0.8 >>l t2.1), (rt0^8.8 <<l (#0x40.1-t2.1)), rt0.8 ; u=rt0.16,t2.1 d=rt0.8
shr rt0^8.8, t2.1, rt0^8.8 ; u=rt0^8.8,t2.1 d=rt0^8.8
mov rt0.8, r8.8 ; u=rt0.8 d=r8.8
lnot of.1, tt.1 ; u=of.1 d=tt.1

```

The same happens for `SHLD`:

```plaintext
or (rt0^8.8 <<l t2.1), (rt0.8 >>l (#0x40.1-t2.1)), rt0^8.8 ; u=rt0.16,t2.1 d=rt0^8.8
shl rt0.8, t2.1, rt0.8 ; u=rt0.8,t2.1 d=rt0.8
mov rt0^8.8, r8.8 ; u=rt0^8.8 d=r8.8
lnot of.1, tt.1 ; u=of.1 d=tt.1

```

In both cases, `of.1` retains the zero assigned by the earlier `xor ecx, ecx`.

At `MMAT_LVARS`, both functions reduce to:

```plaintext
mov #0xDEAD.8, result.8 ; u= d=rax.8

```

And the resulting pseudocode:

```c
return 0xDEAD;

```

Both instructions should produce `OF = 1`, since the sign bit changes with a shift count of one. The correct return value in each case is `0xBEEF`.

This also affects CF, SF, ZF and PF, which are defined for these shift counts but are likewise missing from the generated microcode. For example, the parity test (`cmovp`) produces:

```c
if ( __SETP__ (1, 0) )
    return 0xBEEF;

```

---

<div class="post-metadata">

**Author:** ![teresa\_hexrays](https://sea2.discourse-cdn.com/flex002/user_avatar/community.hex-rays.com/teresa_hexrays/32/11_2.png) [@teresa\_hexrays](https://community.hex-rays.com/u/teresa_hexrays)\
**Post date:** [November 4, 2026, 3:48pm UTC](https://community.hex-rays.com/t/x86-64-shrd-shld-omit-defined-flag-updates/861/2 "2026-11-04T15:48:04Z")

</div>

Thank you - issue logged! We’ll follow up as soon as we have news.
