-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[X86][GlobalISel] Enable G_SDIV/G_UDIV/G_SREM/G_UREM #81615
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
82c4e50
[X86][GlobalISel] Enable G_SDIV/G_UDIV/G_SREM/G_UREM
e-kud aec6cd2
Unify MIR legalizer tests
e-kud 30d4578
Merge remote-tracking branch 'origin/main' into global-div-rem
e-kud 07459c4
Remove alignment and registers from mir tests
e-kud f871f65
Drop IR from mir tests
e-kud e0c884c
Merge branch 'main' into global-div-rem
e-kud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py | ||
# RUN: llc -mtriple=x86_64-linux-gnu -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=CHECK,X64 | ||
# RUN: llc -mtriple=i686-linux-gnu -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=CHECK,X86 | ||
|
||
... | ||
--- | ||
name: test_sdiv_i8 | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1: | ||
liveins: $edi, $esi | ||
|
||
; CHECK-LABEL: name: test_sdiv_i8 | ||
; CHECK: liveins: $edi, $esi | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $edi | ||
; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s8) = G_TRUNC [[COPY]](s32) | ||
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $esi | ||
; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s8) = G_TRUNC [[COPY1]](s32) | ||
; CHECK-NEXT: [[SDIV:%[0-9]+]]:_(s8) = G_SDIV [[TRUNC]], [[TRUNC1]] | ||
; CHECK-NEXT: $al = COPY [[SDIV]](s8) | ||
; CHECK-NEXT: RET 0, implicit $al | ||
%2:_(s32) = COPY $edi | ||
%0:_(s8) = G_TRUNC %2(s32) | ||
%3:_(s32) = COPY $esi | ||
%1:_(s8) = G_TRUNC %3(s32) | ||
%4:_(s8) = G_SDIV %0, %1 | ||
$al = COPY %4(s8) | ||
RET 0, implicit $al | ||
|
||
... | ||
--- | ||
name: test_sdiv_i16 | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1: | ||
liveins: $edi, $esi | ||
|
||
; CHECK-LABEL: name: test_sdiv_i16 | ||
; CHECK: liveins: $edi, $esi | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $edi | ||
; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32) | ||
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $esi | ||
; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[COPY1]](s32) | ||
; CHECK-NEXT: [[SDIV:%[0-9]+]]:_(s16) = G_SDIV [[TRUNC]], [[TRUNC1]] | ||
; CHECK-NEXT: $ax = COPY [[SDIV]](s16) | ||
; CHECK-NEXT: RET 0, implicit $ax | ||
%2:_(s32) = COPY $edi | ||
%0:_(s16) = G_TRUNC %2(s32) | ||
%3:_(s32) = COPY $esi | ||
%1:_(s16) = G_TRUNC %3(s32) | ||
%4:_(s16) = G_SDIV %0, %1 | ||
$ax = COPY %4(s16) | ||
RET 0, implicit $ax | ||
|
||
... | ||
--- | ||
name: test_sdiv_i32 | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1: | ||
liveins: $edi, $esi | ||
|
||
; CHECK-LABEL: name: test_sdiv_i32 | ||
; CHECK: liveins: $edi, $esi | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $edi | ||
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $esi | ||
; CHECK-NEXT: [[SDIV:%[0-9]+]]:_(s32) = G_SDIV [[COPY]], [[COPY1]] | ||
; CHECK-NEXT: $eax = COPY [[SDIV]](s32) | ||
; CHECK-NEXT: RET 0, implicit $eax | ||
%0:_(s32) = COPY $edi | ||
%1:_(s32) = COPY $esi | ||
%2:_(s32) = G_SDIV %0, %1 | ||
$eax = COPY %2(s32) | ||
RET 0, implicit $eax | ||
|
||
... | ||
--- | ||
name: test_sdiv_i64 | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1: | ||
; X64-LABEL: name: test_sdiv_i64 | ||
; X64: [[DEF:%[0-9]+]]:_(s64) = IMPLICIT_DEF | ||
; X64-NEXT: [[DEF1:%[0-9]+]]:_(s64) = IMPLICIT_DEF | ||
; X64-NEXT: [[SDIV:%[0-9]+]]:_(s64) = G_SDIV [[DEF]], [[DEF1]] | ||
; X64-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[SDIV]](s64) | ||
; X64-NEXT: RET 0, implicit [[COPY]](s64) | ||
; | ||
; X86-LABEL: name: test_sdiv_i64 | ||
; X86: [[DEF:%[0-9]+]]:_(s64) = IMPLICIT_DEF | ||
; X86-NEXT: [[DEF1:%[0-9]+]]:_(s64) = IMPLICIT_DEF | ||
; X86-NEXT: ADJCALLSTACKDOWN32 16, 0, 0, implicit-def $esp, implicit-def $eflags, implicit-def $ssp, implicit $esp, implicit $ssp | ||
; X86-NEXT: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[DEF]](s64) | ||
; X86-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $esp | ||
; X86-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0 | ||
; X86-NEXT: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[C]](s32) | ||
; X86-NEXT: G_STORE [[UV]](s32), [[PTR_ADD]](p0) :: (store (s32) into stack, align 1) | ||
; X86-NEXT: [[COPY1:%[0-9]+]]:_(p0) = COPY $esp | ||
; X86-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 4 | ||
; X86-NEXT: [[PTR_ADD1:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY1]], [[C1]](s32) | ||
; X86-NEXT: G_STORE [[UV1]](s32), [[PTR_ADD1]](p0) :: (store (s32) into stack + 4, align 1) | ||
; X86-NEXT: [[UV2:%[0-9]+]]:_(s32), [[UV3:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[DEF1]](s64) | ||
; X86-NEXT: [[COPY2:%[0-9]+]]:_(p0) = COPY $esp | ||
; X86-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 8 | ||
; X86-NEXT: [[PTR_ADD2:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY2]], [[C2]](s32) | ||
; X86-NEXT: G_STORE [[UV2]](s32), [[PTR_ADD2]](p0) :: (store (s32) into stack + 8, align 1) | ||
; X86-NEXT: [[COPY3:%[0-9]+]]:_(p0) = COPY $esp | ||
; X86-NEXT: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 12 | ||
; X86-NEXT: [[PTR_ADD3:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY3]], [[C3]](s32) | ||
; X86-NEXT: G_STORE [[UV3]](s32), [[PTR_ADD3]](p0) :: (store (s32) into stack + 12, align 1) | ||
; X86-NEXT: CALLpcrel32 &__divdi3, csr_32, implicit $esp, implicit $ssp, implicit-def $eax, implicit-def $edx | ||
; X86-NEXT: [[COPY4:%[0-9]+]]:_(s32) = COPY $eax | ||
; X86-NEXT: [[COPY5:%[0-9]+]]:_(s32) = COPY $edx | ||
; X86-NEXT: [[MV:%[0-9]+]]:_(s64) = G_MERGE_VALUES [[COPY4]](s32), [[COPY5]](s32) | ||
; X86-NEXT: ADJCALLSTACKUP32 16, 0, implicit-def $esp, implicit-def $eflags, implicit-def $ssp, implicit $esp, implicit $ssp | ||
; X86-NEXT: [[COPY6:%[0-9]+]]:_(s64) = COPY [[MV]](s64) | ||
; X86-NEXT: RET 0, implicit [[COPY6]](s64) | ||
%0:_(s64) = IMPLICIT_DEF | ||
%1:_(s64) = IMPLICIT_DEF | ||
%2:_(s64) = G_SDIV %0, %1 | ||
%3:_(s64) = COPY %2(s64) | ||
RET 0, implicit %3 | ||
|
||
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py | ||
# RUN: llc -mtriple=x86_64-linux-gnu -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=CHECK,X64 | ||
# RUN: llc -mtriple=i686-linux-gnu -run-pass=legalizer -verify-machineinstrs %s -o - | FileCheck %s --check-prefixes=CHECK,X86 | ||
|
||
... | ||
--- | ||
name: test_srem_i8 | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1: | ||
liveins: $edi, $esi | ||
|
||
; CHECK-LABEL: name: test_srem_i8 | ||
; CHECK: liveins: $edi, $esi | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $edi | ||
; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s8) = G_TRUNC [[COPY]](s32) | ||
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $esi | ||
; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s8) = G_TRUNC [[COPY1]](s32) | ||
; CHECK-NEXT: [[SREM:%[0-9]+]]:_(s8) = G_SREM [[TRUNC]], [[TRUNC1]] | ||
; CHECK-NEXT: $al = COPY [[SREM]](s8) | ||
; CHECK-NEXT: RET 0, implicit $al | ||
%2:_(s32) = COPY $edi | ||
%0:_(s8) = G_TRUNC %2(s32) | ||
%3:_(s32) = COPY $esi | ||
%1:_(s8) = G_TRUNC %3(s32) | ||
%4:_(s8) = G_SREM %0, %1 | ||
$al = COPY %4(s8) | ||
RET 0, implicit $al | ||
|
||
... | ||
--- | ||
name: test_srem_i16 | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1: | ||
liveins: $edi, $esi | ||
|
||
; CHECK-LABEL: name: test_srem_i16 | ||
; CHECK: liveins: $edi, $esi | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $edi | ||
; CHECK-NEXT: [[TRUNC:%[0-9]+]]:_(s16) = G_TRUNC [[COPY]](s32) | ||
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $esi | ||
; CHECK-NEXT: [[TRUNC1:%[0-9]+]]:_(s16) = G_TRUNC [[COPY1]](s32) | ||
; CHECK-NEXT: [[SREM:%[0-9]+]]:_(s16) = G_SREM [[TRUNC]], [[TRUNC1]] | ||
; CHECK-NEXT: $ax = COPY [[SREM]](s16) | ||
; CHECK-NEXT: RET 0, implicit $ax | ||
%2:_(s32) = COPY $edi | ||
%0:_(s16) = G_TRUNC %2(s32) | ||
%3:_(s32) = COPY $esi | ||
%1:_(s16) = G_TRUNC %3(s32) | ||
%4:_(s16) = G_SREM %0, %1 | ||
$ax = COPY %4(s16) | ||
RET 0, implicit $ax | ||
|
||
... | ||
--- | ||
name: test_srem_i32 | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1: | ||
liveins: $edi, $esi | ||
|
||
; CHECK-LABEL: name: test_srem_i32 | ||
; CHECK: liveins: $edi, $esi | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $edi | ||
; CHECK-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $esi | ||
; CHECK-NEXT: [[SREM:%[0-9]+]]:_(s32) = G_SREM [[COPY]], [[COPY1]] | ||
; CHECK-NEXT: $eax = COPY [[SREM]](s32) | ||
; CHECK-NEXT: RET 0, implicit $eax | ||
%0:_(s32) = COPY $edi | ||
%1:_(s32) = COPY $esi | ||
%2:_(s32) = G_SREM %0, %1 | ||
$eax = COPY %2(s32) | ||
RET 0, implicit $eax | ||
|
||
... | ||
--- | ||
name: test_srem_i64 | ||
tracksRegLiveness: true | ||
body: | | ||
bb.1: | ||
; X64-LABEL: name: test_srem_i64 | ||
; X64: [[DEF:%[0-9]+]]:_(s64) = IMPLICIT_DEF | ||
; X64-NEXT: [[DEF1:%[0-9]+]]:_(s64) = IMPLICIT_DEF | ||
; X64-NEXT: [[SREM:%[0-9]+]]:_(s64) = G_SREM [[DEF]], [[DEF1]] | ||
; X64-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY [[SREM]](s64) | ||
; X64-NEXT: RET 0, implicit [[COPY]](s64) | ||
; | ||
; X86-LABEL: name: test_srem_i64 | ||
; X86: [[DEF:%[0-9]+]]:_(s64) = IMPLICIT_DEF | ||
; X86-NEXT: [[DEF1:%[0-9]+]]:_(s64) = IMPLICIT_DEF | ||
; X86-NEXT: ADJCALLSTACKDOWN32 16, 0, 0, implicit-def $esp, implicit-def $eflags, implicit-def $ssp, implicit $esp, implicit $ssp | ||
; X86-NEXT: [[UV:%[0-9]+]]:_(s32), [[UV1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[DEF]](s64) | ||
; X86-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $esp | ||
; X86-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0 | ||
; X86-NEXT: [[PTR_ADD:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY]], [[C]](s32) | ||
; X86-NEXT: G_STORE [[UV]](s32), [[PTR_ADD]](p0) :: (store (s32) into stack, align 1) | ||
; X86-NEXT: [[COPY1:%[0-9]+]]:_(p0) = COPY $esp | ||
; X86-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 4 | ||
; X86-NEXT: [[PTR_ADD1:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY1]], [[C1]](s32) | ||
; X86-NEXT: G_STORE [[UV1]](s32), [[PTR_ADD1]](p0) :: (store (s32) into stack + 4, align 1) | ||
; X86-NEXT: [[UV2:%[0-9]+]]:_(s32), [[UV3:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[DEF1]](s64) | ||
; X86-NEXT: [[COPY2:%[0-9]+]]:_(p0) = COPY $esp | ||
; X86-NEXT: [[C2:%[0-9]+]]:_(s32) = G_CONSTANT i32 8 | ||
; X86-NEXT: [[PTR_ADD2:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY2]], [[C2]](s32) | ||
; X86-NEXT: G_STORE [[UV2]](s32), [[PTR_ADD2]](p0) :: (store (s32) into stack + 8, align 1) | ||
; X86-NEXT: [[COPY3:%[0-9]+]]:_(p0) = COPY $esp | ||
; X86-NEXT: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 12 | ||
; X86-NEXT: [[PTR_ADD3:%[0-9]+]]:_(p0) = G_PTR_ADD [[COPY3]], [[C3]](s32) | ||
; X86-NEXT: G_STORE [[UV3]](s32), [[PTR_ADD3]](p0) :: (store (s32) into stack + 12, align 1) | ||
; X86-NEXT: CALLpcrel32 &__moddi3, csr_32, implicit $esp, implicit $ssp, implicit-def $eax, implicit-def $edx | ||
; X86-NEXT: [[COPY4:%[0-9]+]]:_(s32) = COPY $eax | ||
; X86-NEXT: [[COPY5:%[0-9]+]]:_(s32) = COPY $edx | ||
; X86-NEXT: [[MV:%[0-9]+]]:_(s64) = G_MERGE_VALUES [[COPY4]](s32), [[COPY5]](s32) | ||
; X86-NEXT: ADJCALLSTACKUP32 16, 0, implicit-def $esp, implicit-def $eflags, implicit-def $ssp, implicit $esp, implicit $ssp | ||
; X86-NEXT: [[COPY6:%[0-9]+]]:_(s64) = COPY [[MV]](s64) | ||
; X86-NEXT: RET 0, implicit [[COPY6]](s64) | ||
%0:_(s64) = IMPLICIT_DEF | ||
%1:_(s64) = IMPLICIT_DEF | ||
%2:_(s64) = G_SREM %0, %1 | ||
%3:_(s64) = COPY %2(s64) | ||
RET 0, implicit %3 | ||
|
||
... |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably for another patch, but we should match SelectionDAG here and use a MOVZX_NOREX or MOVSX_NOREX from AH here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean to replace
COPY
+SHR
bymovzx %ah, %ax
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is the code from X86ISelDAGToDAG.cpp