-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[X86][CodeGen] Support using NF instructions for flag copy lowering #93508
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
Changes from all commits
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,90 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+nf | FileCheck %s | ||
|
||
define i32 @flag_copy_1(i32 %x, i32 %y, ptr %pz) nounwind { | ||
; CHECK-LABEL: flag_copy_1: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: movq %rdx, %rcx | ||
; CHECK-NEXT: movl %edi, %eax | ||
; CHECK-NEXT: mull %esi | ||
; CHECK-NEXT: movl (%rcx), %ecx | ||
; CHECK-NEXT: {nf} addl %eax, %ecx | ||
; CHECK-NEXT: cmovol %ecx, %eax | ||
; CHECK-NEXT: retq | ||
%o = tail call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %x, i32 %y) | ||
%v1 = extractvalue { i32, i1 } %o, 1 | ||
%v2 = extractvalue { i32, i1 } %o, 0 | ||
%z = load i32, ptr %pz | ||
%a = add i32 %v2, %z | ||
%r = select i1 %v1, i32 %a, i32 %v2 | ||
ret i32 %r | ||
} | ||
|
||
declare <2 x i128> @llvm.ssub.sat.v2i128(<2 x i128>, <2 x i128>) | ||
|
||
define <2 x i128> @flag_copy_2(<2 x i128> %x, <2 x i128> %y) nounwind { | ||
; CHECK-LABEL: flag_copy_2: | ||
; CHECK: # %bb.0: | ||
; CHECK-NEXT: movq %rdi, %rax | ||
; CHECK-NEXT: subq {{[0-9]+}}(%rsp), %rcx | ||
; CHECK-NEXT: sbbq {{[0-9]+}}(%rsp), %r8 | ||
; CHECK-NEXT: movq %r8, %rdi | ||
; CHECK-NEXT: {nf} sarq $63, %rdi | ||
; CHECK-NEXT: cmovoq %rdi, %rcx | ||
; CHECK-NEXT: movabsq $-9223372036854775808, %r9 # imm = 0x8000000000000000 | ||
; CHECK-NEXT: {nf} xorq %r9, %rdi | ||
; CHECK-NEXT: cmovnoq %r8, %rdi | ||
; CHECK-NEXT: subq {{[0-9]+}}(%rsp), %rsi | ||
; CHECK-NEXT: sbbq {{[0-9]+}}(%rsp), %rdx | ||
; CHECK-NEXT: movq %rdx, %r8 | ||
; CHECK-NEXT: {nf} sarq $63, %r8 | ||
; CHECK-NEXT: cmovoq %r8, %rsi | ||
; CHECK-NEXT: {nf} xorq %r9, %r8 | ||
; CHECK-NEXT: cmovnoq %rdx, %r8 | ||
; CHECK-NEXT: movq %rcx, 16(%rax) | ||
; CHECK-NEXT: movq %rsi, (%rax) | ||
; CHECK-NEXT: movq %rdi, 24(%rax) | ||
; CHECK-NEXT: movq %r8, 8(%rax) | ||
; CHECK-NEXT: retq | ||
%z = call <2 x i128> @llvm.ssub.sat.v2i128(<2 x i128> %x, <2 x i128> %y) | ||
ret <2 x i128> %z | ||
} | ||
|
||
; TODO: Remove the 2nd cmpl by using NF imul. | ||
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. I checked with this, firstly this was done by That means, We can always assume the def and use of 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. Offline talked with Phoebe. We need to traverse BBs, and at the same time, we need to update liveins of BBs. 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. Done @phoebewang |
||
define void @flag_copy_3(i32 %x, i32 %y, ptr %pa, ptr %pb, ptr %pc) nounwind { | ||
; CHECK-LABEL: flag_copy_3: | ||
; CHECK: # %bb.0: # %entry | ||
; CHECK-NEXT: # kill: def $esi killed $esi def $rsi | ||
; CHECK-NEXT: cmpl $2, %edi | ||
; CHECK-NEXT: jl .LBB2_2 | ||
; CHECK-NEXT: # %bb.1: # %bb1 | ||
; CHECK-NEXT: movl %edi, %eax | ||
; CHECK-NEXT: imull %esi, %eax | ||
; CHECK-NEXT: movl %eax, (%rdx) | ||
; CHECK-NEXT: jmp .LBB2_3 | ||
; CHECK-NEXT: .LBB2_2: # %bb2 | ||
; CHECK-NEXT: leal -2(%rsi), %eax | ||
; CHECK-NEXT: movl %eax, (%rcx) | ||
; CHECK-NEXT: .LBB2_3: # %bb3 | ||
; CHECK-NEXT: cmpl $2, %edi | ||
; CHECK-NEXT: cmovgel %edi, %esi | ||
; CHECK-NEXT: movl %esi, (%r8) | ||
; CHECK-NEXT: retq | ||
entry: | ||
%cmp = icmp sgt i32 %x, 1 | ||
br i1 %cmp, label %bb1, label %bb2 | ||
bb1: | ||
%add = mul nuw nsw i32 %x, %y | ||
store i32 %add, ptr %pa | ||
br label %bb3 | ||
|
||
bb2: | ||
%sub = sub nuw nsw i32 %y, 2 | ||
store i32 %sub, ptr %pb | ||
br label %bb3 | ||
|
||
bb3: | ||
%s = select i1 %cmp, i32 %x, i32 %y | ||
store i32 %s, ptr %pc | ||
ret void | ||
} |
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.
Can't this be failed? I think we cannot transform another
$eflags = COPY %x
inMBB
at least, right?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.
Then it's a InevitableClobber and handled at line 323.