-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[X86] Fold some (truncate (srl (add X, C1), C2)) patterns to (add (truncate (srl X, C2)), C1') #126448
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
[X86] Fold some (truncate (srl (add X, C1), C2)) patterns to (add (truncate (srl X, C2)), C1') #126448
Changes from all commits
3d73525
f530899
a9d77fd
bd8a2ef
b773400
b526b0f
e6fc7f0
55d53f5
8d3556e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc < %s -mtriple=x86_64-unknown | FileCheck %s --check-prefixes=X64 | ||
|
||
; Test for https://github.com/llvm/llvm-project/issues/123239 | ||
|
||
define i1 @test_ult_trunc_add(i64 %x) { | ||
; X64-LABEL: test_ult_trunc_add: | ||
; X64: # %bb.0: | ||
; X64-NEXT: shrq $48, %rdi | ||
; X64-NEXT: addl $-65522, %edi # imm = 0xFFFF000E | ||
; X64-NEXT: cmpl $3, %edi | ||
; X64-NEXT: setb %al | ||
; X64-NEXT: retq | ||
%add = add i64 %x, 3940649673949184 | ||
%shr = lshr i64 %add, 48 | ||
%conv = trunc i64 %shr to i32 | ||
%res = icmp ult i32 %conv, 3 | ||
ret i1 %res | ||
} | ||
|
||
define i1 @test_ult_add(i64 %x) { | ||
; X64-LABEL: test_ult_add: | ||
; X64: # %bb.0: | ||
; X64-NEXT: shrq $48, %rdi | ||
; X64-NEXT: addl $-65522, %edi # imm = 0xFFFF000E | ||
; X64-NEXT: cmpl $3, %edi | ||
; X64-NEXT: setb %al | ||
; X64-NEXT: retq | ||
%add = add i64 3940649673949184, %x | ||
%cmp = icmp ult i64 %add, 844424930131968 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @test_ugt_trunc_add(i64 %x) { | ||
; X64-LABEL: test_ugt_trunc_add: | ||
; X64: # %bb.0: | ||
; X64-NEXT: shrq $48, %rdi | ||
; X64-NEXT: addl $-65522, %edi # imm = 0xFFFF000E | ||
; X64-NEXT: cmpl $4, %edi | ||
; X64-NEXT: setae %al | ||
; X64-NEXT: retq | ||
%add = add i64 %x, 3940649673949184 | ||
%shr = lshr i64 %add, 48 | ||
%conv = trunc i64 %shr to i32 | ||
%res = icmp ugt i32 %conv, 3 | ||
ret i1 %res | ||
} | ||
|
||
define i1 @test_ugt_add(i64 %x) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are these negative tests? Add comments if they are. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this transformation is also applicable to those tests. However, the selection DAG differs in those cases, so I figured expanding the transformation to include them should be a separate patch. If preferred, I can expand it now, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's ok to do in a separate patch. |
||
; X64-LABEL: test_ugt_add: | ||
; X64: # %bb.0: | ||
; X64-NEXT: movabsq $3940649673949184, %rax # imm = 0xE000000000000 | ||
; X64-NEXT: addq %rdi, %rax | ||
; X64-NEXT: movabsq $844424930131968, %rcx # imm = 0x3000000000000 | ||
; X64-NEXT: cmpq %rcx, %rax | ||
; X64-NEXT: seta %al | ||
; X64-NEXT: retq | ||
%add = add i64 3940649673949184, %x | ||
%cmp = icmp ugt i64 %add, 844424930131968 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @test_eq_trunc_add(i64 %x) { | ||
; X64-LABEL: test_eq_trunc_add: | ||
; X64: # %bb.0: | ||
; X64-NEXT: shrq $48, %rdi | ||
; X64-NEXT: cmpl $65525, %edi # imm = 0xFFF5 | ||
; X64-NEXT: sete %al | ||
; X64-NEXT: retq | ||
%add = add i64 %x, 3940649673949184 | ||
%shr = lshr i64 %add, 48 | ||
%conv = trunc i64 %shr to i32 | ||
%res = icmp eq i32 %conv, 3 | ||
ret i1 %res | ||
} | ||
|
||
define i1 @test_eq_add(i64 %x) { | ||
; X64-LABEL: test_eq_add: | ||
; X64: # %bb.0: | ||
; X64-NEXT: movabsq $-3096224743817216, %rax # imm = 0xFFF5000000000000 | ||
; X64-NEXT: cmpq %rax, %rdi | ||
; X64-NEXT: sete %al | ||
; X64-NEXT: retq | ||
%add = add i64 3940649673949184, %x | ||
%cmp = icmp eq i64 %add, 844424930131968 | ||
ret i1 %cmp | ||
} | ||
|
||
define i1 @test_ne_trunc_add(i64 %x) { | ||
; X64-LABEL: test_ne_trunc_add: | ||
; X64: # %bb.0: | ||
; X64-NEXT: shrq $48, %rdi | ||
; X64-NEXT: cmpl $65525, %edi # imm = 0xFFF5 | ||
; X64-NEXT: setne %al | ||
; X64-NEXT: retq | ||
%add = add i64 %x, 3940649673949184 | ||
%shr = lshr i64 %add, 48 | ||
%conv = trunc i64 %shr to i32 | ||
%res = icmp ne i32 %conv, 3 | ||
ret i1 %res | ||
} | ||
|
||
define i1 @test_ne_add(i64 %x) { | ||
; X64-LABEL: test_ne_add: | ||
; X64: # %bb.0: | ||
; X64-NEXT: movabsq $-3096224743817216, %rax # imm = 0xFFF5000000000000 | ||
; X64-NEXT: cmpq %rax, %rdi | ||
; X64-NEXT: setne %al | ||
; X64-NEXT: retq | ||
%add = add i64 3940649673949184, %x | ||
%cmp = icmp ne i64 %add, 844424930131968 | ||
ret i1 %cmp | ||
} | ||
|
||
define i32 @test_trunc_add(i64 %x) { | ||
; X64-LABEL: test_trunc_add: | ||
; X64: # %bb.0: | ||
; X64-NEXT: shrq $48, %rdi | ||
; X64-NEXT: leal -65522(%rdi), %eax | ||
; X64-NEXT: retq | ||
%add = add i64 %x, 3940649673949184 | ||
%shr = lshr i64 %add, 48 | ||
%conv = trunc i64 %shr to i32 | ||
ret i32 %conv | ||
} |
Uh oh!
There was an error while loading. Please reload this page.