-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DAG] Reducing instructions by better legalization handling of AVGFLOORU for illegal data types #99913
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
topperc
merged 14 commits into
llvm:main
from
wizardengineer:_DAG_Reducing_instructions_by_better_legalization_handling_for_i128_data_types
Jul 28, 2024
Merged
[DAG] Reducing instructions by better legalization handling of AVGFLOORU for illegal data types #99913
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b3078d1
Uploaded test without optimization
wizardengineer d3a909e
Uploaded test with optimization
wizardengineer 8881fca
the legalization of i128
wizardengineer 2bb628d
Reuploaded the test without optimization
wizardengineer 74b4c96
Reuploaded the test with optimization
wizardengineer 7bbee40
Not limited to i128 anymore and other fixes
wizardengineer 9e3cb4c
Renamed test files and added reasoning behind negative test cases
wizardengineer 1b4573c
proper format with other simple changes
wizardengineer de26c67
remove unused variable
wizardengineer 3407bd4
regenerated the test files after removing the Select instruction
wizardengineer 1fefa25
test files without opt
wizardengineer 09ab202
test files generated with opt
wizardengineer 58e3b63
regenerated for other tests
wizardengineer a9d8077
removed comment and added expansion in comment
wizardengineer 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc -mtriple=aarch64 < %s | FileCheck %s | ||
|
||
define i128 @avgflooru_i128(i128 %x, i128 %y) { | ||
; CHECK-LABEL: avgflooru_i128: | ||
; CHECK: // %bb.0: // %start | ||
; CHECK-NEXT: adds x8, x0, x2 | ||
; CHECK-NEXT: adcs x9, x1, x3 | ||
; CHECK-NEXT: cset w10, hs | ||
; CHECK-NEXT: extr x0, x9, x8, #1 | ||
; CHECK-NEXT: extr x1, x10, x9, #1 | ||
; CHECK-NEXT: ret | ||
start: | ||
%xor = xor i128 %y, %x | ||
%lshr = lshr i128 %xor, 1 | ||
%and = and i128 %y, %x | ||
%add = add i128 %lshr, %and | ||
ret i128 %add | ||
} | ||
|
||
declare void @use(i8) | ||
|
||
define i128 @avgflooru_i128_multi_use(i128 %x, i128 %y) nounwind { | ||
; CHECK-LABEL: avgflooru_i128_multi_use: | ||
; CHECK: // %bb.0: // %start | ||
; CHECK-NEXT: str x30, [sp, #-64]! // 8-byte Folded Spill | ||
; CHECK-NEXT: stp x24, x23, [sp, #16] // 16-byte Folded Spill | ||
; CHECK-NEXT: eor x23, x3, x1 | ||
; CHECK-NEXT: eor x24, x2, x0 | ||
; CHECK-NEXT: stp x22, x21, [sp, #32] // 16-byte Folded Spill | ||
; CHECK-NEXT: mov x21, x1 | ||
; CHECK-NEXT: mov x22, x0 | ||
; CHECK-NEXT: mov x0, x24 | ||
; CHECK-NEXT: mov x1, x23 | ||
; CHECK-NEXT: stp x20, x19, [sp, #48] // 16-byte Folded Spill | ||
; CHECK-NEXT: mov x19, x3 | ||
; CHECK-NEXT: mov x20, x2 | ||
; CHECK-NEXT: bl use | ||
; CHECK-NEXT: extr x0, x23, x24, #1 | ||
; CHECK-NEXT: lsr x1, x23, #1 | ||
; CHECK-NEXT: bl use | ||
; CHECK-NEXT: adds x8, x22, x20 | ||
; CHECK-NEXT: ldp x24, x23, [sp, #16] // 16-byte Folded Reload | ||
; CHECK-NEXT: adcs x9, x21, x19 | ||
; CHECK-NEXT: ldp x20, x19, [sp, #48] // 16-byte Folded Reload | ||
; CHECK-NEXT: ldp x22, x21, [sp, #32] // 16-byte Folded Reload | ||
; CHECK-NEXT: cset w10, hs | ||
; CHECK-NEXT: extr x0, x9, x8, #1 | ||
; CHECK-NEXT: extr x1, x10, x9, #1 | ||
; CHECK-NEXT: ldr x30, [sp], #64 // 8-byte Folded Reload | ||
; CHECK-NEXT: ret | ||
start: | ||
%xor = xor i128 %y, %x | ||
call void @use(i128 %xor) | ||
%lshr = lshr i128 %xor, 1 | ||
call void @use(i128 %lshr) | ||
%and = and i128 %y, %x | ||
%add = add i128 %lshr, %and | ||
ret i128 %add | ||
} | ||
|
||
; the 'avgflooru_i128_negative` shouldn't combine because it's not | ||
; an avgflooru operation, which is what we're targeting | ||
|
||
define i128 @avgflooru_i128_negative(i128 %x, i128 %y) { | ||
; CHECK-LABEL: avgflooru_i128_negative: | ||
; CHECK: // %bb.0: // %start | ||
; CHECK-NEXT: mvn x8, x0 | ||
; CHECK-NEXT: and x9, x2, x0 | ||
; CHECK-NEXT: mvn x10, x1 | ||
; CHECK-NEXT: and x11, x3, x1 | ||
; CHECK-NEXT: adds x0, x8, x9 | ||
; CHECK-NEXT: adc x1, x10, x11 | ||
; CHECK-NEXT: ret | ||
start: | ||
%xor = xor i128 %x, -1 | ||
%and = and i128 %y, %x | ||
%add = add i128 %xor, %and | ||
ret i128 %add | ||
} | ||
|
||
; This negative test case shouldn't work, i32 is already properly | ||
; handled in terms of legalization, compared to the i128 | ||
|
||
define i32 @avgflooru_i128_negative2(i32 %x, i32 %y) { | ||
; CHECK-LABEL: avgflooru_i128_negative2: | ||
; CHECK: // %bb.0: // %start | ||
; CHECK-NEXT: mov w8, w1 | ||
; CHECK-NEXT: add x8, x8, w0, uxtw | ||
; CHECK-NEXT: lsr x0, x8, #1 | ||
; CHECK-NEXT: // kill: def $w0 killed $w0 killed $x0 | ||
; CHECK-NEXT: ret | ||
start: | ||
%xor = xor i32 %y, %x | ||
%lshr = lshr i32 %xor, 1 | ||
%and = and i32 %y, %x | ||
%add = add i32 %lshr, %and | ||
ret i32 %add | ||
} | ||
|
||
define <2 x i128> @avgflooru_i128_vec(<2 x i128> %x, <2 x i128> %y) { | ||
; CHECK-LABEL: avgflooru_i128_vec: | ||
; CHECK: // %bb.0: // %start | ||
; CHECK-NEXT: adds x8, x0, x4 | ||
; CHECK-NEXT: adcs x9, x1, x5 | ||
; CHECK-NEXT: cset w10, hs | ||
; CHECK-NEXT: adds x11, x2, x6 | ||
; CHECK-NEXT: extr x0, x9, x8, #1 | ||
; CHECK-NEXT: adcs x12, x3, x7 | ||
; CHECK-NEXT: extr x1, x10, x9, #1 | ||
; CHECK-NEXT: extr x11, x12, x11, #1 | ||
; CHECK-NEXT: cset w13, hs | ||
; CHECK-NEXT: extr x3, x13, x12, #1 | ||
; CHECK-NEXT: fmov d0, x11 | ||
; CHECK-NEXT: mov v0.d[1], x3 | ||
; CHECK-NEXT: fmov x2, d0 | ||
; CHECK-NEXT: ret | ||
start: | ||
%xor = xor <2 x i128> %y, %x | ||
%lshr = lshr <2 x i128> %xor, <i128 1, i128 1> | ||
%and = and <2 x i128> %y, %x | ||
%add = add <2 x i128> %lshr, %and | ||
ret <2 x i128> %add | ||
} |
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,145 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc -mtriple=x86_64 < %s | FileCheck %s | ||
|
||
define i128 @avgflooru_i128(i128 %x, i128 %y) { | ||
; CHECK-LABEL: avgflooru_i128: | ||
; CHECK: # %bb.0: # %start | ||
; CHECK-NEXT: movq %rdi, %rax | ||
; CHECK-NEXT: addq %rdx, %rax | ||
; CHECK-NEXT: adcq %rcx, %rsi | ||
; CHECK-NEXT: setb %cl | ||
; CHECK-NEXT: shrdq $1, %rsi, %rax | ||
; CHECK-NEXT: movzbl %cl, %edx | ||
; CHECK-NEXT: shldq $63, %rsi, %rdx | ||
; CHECK-NEXT: retq | ||
start: | ||
%xor = xor i128 %y, %x | ||
%lshr = lshr i128 %xor, 1 | ||
%and = and i128 %y, %x | ||
%add = add i128 %lshr, %and | ||
ret i128 %add | ||
} | ||
|
||
declare void @use(i8) | ||
|
||
define i128 @avgflooru_i128_multi_use(i128 %x, i128 %y) nounwind { | ||
; CHECK-LABEL: avgflooru_i128_multi_use: | ||
; CHECK: # %bb.0: # %start | ||
; CHECK-NEXT: pushq %rbp | ||
; CHECK-NEXT: pushq %r15 | ||
; CHECK-NEXT: pushq %r14 | ||
; CHECK-NEXT: pushq %r13 | ||
; CHECK-NEXT: pushq %r12 | ||
; CHECK-NEXT: pushq %rbx | ||
; CHECK-NEXT: pushq %rax | ||
; CHECK-NEXT: movq %rcx, %rbx | ||
; CHECK-NEXT: movq %rdx, %r14 | ||
; CHECK-NEXT: movq %rsi, %r15 | ||
; CHECK-NEXT: movq %rdi, %r12 | ||
; CHECK-NEXT: movq %rdx, %r13 | ||
; CHECK-NEXT: xorq %rdi, %r13 | ||
; CHECK-NEXT: movq %rcx, %rbp | ||
; CHECK-NEXT: xorq %rsi, %rbp | ||
; CHECK-NEXT: movq %r13, %rdi | ||
; CHECK-NEXT: movq %rbp, %rsi | ||
; CHECK-NEXT: callq use@PLT | ||
; CHECK-NEXT: shrdq $1, %rbp, %r13 | ||
; CHECK-NEXT: shrq %rbp | ||
; CHECK-NEXT: movq %r13, %rdi | ||
; CHECK-NEXT: movq %rbp, %rsi | ||
; CHECK-NEXT: callq use@PLT | ||
; CHECK-NEXT: addq %r14, %r12 | ||
; CHECK-NEXT: adcq %rbx, %r15 | ||
; CHECK-NEXT: setb %al | ||
; CHECK-NEXT: shrdq $1, %r15, %r12 | ||
; CHECK-NEXT: movzbl %al, %edx | ||
; CHECK-NEXT: shldq $63, %r15, %rdx | ||
; CHECK-NEXT: movq %r12, %rax | ||
; CHECK-NEXT: addq $8, %rsp | ||
; CHECK-NEXT: popq %rbx | ||
; CHECK-NEXT: popq %r12 | ||
; CHECK-NEXT: popq %r13 | ||
; CHECK-NEXT: popq %r14 | ||
; CHECK-NEXT: popq %r15 | ||
; CHECK-NEXT: popq %rbp | ||
; CHECK-NEXT: retq | ||
start: | ||
%xor = xor i128 %y, %x | ||
call void @use(i128 %xor) | ||
%lshr = lshr i128 %xor, 1 | ||
call void @use(i128 %lshr) | ||
%and = and i128 %y, %x | ||
%add = add i128 %lshr, %and | ||
ret i128 %add | ||
} | ||
|
||
; This test case shouldn't combine because it's not | ||
; an avgflooru operation | ||
|
||
define i128 @avgflooru_i128_negative(i128 %x, i128 %y) { | ||
; CHECK-LABEL: avgflooru_i128_negative: | ||
; CHECK: # %bb.0: # %start | ||
; CHECK-NEXT: movq %rdi, %rax | ||
; CHECK-NEXT: andq %rsi, %rcx | ||
; CHECK-NEXT: notq %rsi | ||
; CHECK-NEXT: andq %rdi, %rdx | ||
; CHECK-NEXT: notq %rax | ||
; CHECK-NEXT: addq %rdx, %rax | ||
; CHECK-NEXT: adcq %rcx, %rsi | ||
; CHECK-NEXT: movq %rsi, %rdx | ||
; CHECK-NEXT: retq | ||
start: | ||
%xor = xor i128 %x, -1 | ||
%and = and i128 %y, %x | ||
%add = add i128 %xor, %and | ||
ret i128 %add | ||
} | ||
|
||
; This negative test case shouldn't combine, i32 is already properly | ||
; handled in terms of legalization, compared to the i128 | ||
|
||
define i32 @avgflooru_i128_negative2(i32 %x, i32 %y) { | ||
; CHECK-LABEL: avgflooru_i128_negative2: | ||
; CHECK: # %bb.0: # %start | ||
; CHECK-NEXT: movl %edi, %ecx | ||
; CHECK-NEXT: movl %esi, %eax | ||
; CHECK-NEXT: addq %rcx, %rax | ||
; CHECK-NEXT: shrq %rax | ||
; CHECK-NEXT: # kill: def $eax killed $eax killed $rax | ||
; CHECK-NEXT: retq | ||
start: | ||
%xor = xor i32 %y, %x | ||
%lshr = lshr i32 %xor, 1 | ||
%and = and i32 %y, %x | ||
%add = add i32 %lshr, %and | ||
ret i32 %add | ||
} | ||
|
||
define <2 x i128> @avgflooru_i128_vec(<2 x i128> %x, <2 x i128> %y) { | ||
; CHECK-LABEL: avgflooru_i128_vec: | ||
; CHECK: # %bb.0: # %start | ||
; CHECK-NEXT: movq %rdi, %rax | ||
; CHECK-NEXT: addq {{[0-9]+}}(%rsp), %rsi | ||
; CHECK-NEXT: adcq {{[0-9]+}}(%rsp), %rdx | ||
; CHECK-NEXT: setb %dil | ||
; CHECK-NEXT: movzbl %dil, %edi | ||
; CHECK-NEXT: shldq $63, %rdx, %rdi | ||
; CHECK-NEXT: addq {{[0-9]+}}(%rsp), %rcx | ||
; CHECK-NEXT: adcq {{[0-9]+}}(%rsp), %r8 | ||
; CHECK-NEXT: setb %r9b | ||
; CHECK-NEXT: movzbl %r9b, %r9d | ||
; CHECK-NEXT: shldq $63, %r8, %r9 | ||
; CHECK-NEXT: shldq $63, %rsi, %rdx | ||
; CHECK-NEXT: shldq $63, %rcx, %r8 | ||
; CHECK-NEXT: movq %r8, 16(%rax) | ||
; CHECK-NEXT: movq %rdx, (%rax) | ||
; CHECK-NEXT: movq %r9, 24(%rax) | ||
; CHECK-NEXT: movq %rdi, 8(%rax) | ||
; CHECK-NEXT: retq | ||
start: | ||
%xor = xor <2 x i128> %y, %x | ||
%lshr = lshr <2 x i128> %xor, <i128 1, i128 1> | ||
%and = and <2 x i128> %y, %x | ||
%add = add <2 x i128> %lshr, %and | ||
ret <2 x i128> %add | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.