Skip to content

Instconsistent sdiv and srem by pow2 codegen under Oz #51823

Closed
@topperc

Description

@topperc
Bugzilla Link 52481
Version trunk
OS All
CC @topperc,@RKSimon,@phoebewang,@rotateright

Extended Description

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.

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzillagood first issuehttps://github.com/llvm/llvm-project/contributellvm:SelectionDAGSelectionDAGISel as well

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions