[llvm-bugs] [Bug 52481] New: Instconsistent sdiv and srem by pow2 codegen under Oz

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Nov 11 12:54:40 PST 2021


https://bugs.llvm.org/show_bug.cgi?id=52481

            Bug ID: 52481
           Summary: Instconsistent sdiv and srem by pow2 codegen under Oz
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: craig.topper at gmail.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, pengfei.wang at intel.com,
                    spatel+llvm at rotateright.com

There seems to be an ordering issue in our handling of sdiv/srem by constant
handling under -Oz.

These two test cases produce different code just from reordering the div and
rem

int foo(int x, int *rem) {
  *rem = x % 256;
  return x / 256;
}

int bar(int x, int *div) {
  *div = x / 256;
  return x % 256;
}

foo:                                    # @foo
        mov     ecx, 256
        mov     eax, edi
        cdq
        idiv    ecx
        mov     ecx, eax
        shl     ecx, 8
        sub     edi, ecx
        mov     dword ptr [rsi], edi
        ret
bar:                                    # @bar
        mov     eax, edi
        mov     ecx, 256
        cdq
        idiv    ecx
        mov     dword ptr [rsi], eax
        mov     eax, edx
        ret

bar is using the remainder from the idiv, while foo is using the quotient to
compute the remainder.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20211111/fba599c0/attachment.html>


More information about the llvm-bugs mailing list