Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 101 additions & 38 deletions llvm/test/CodeGen/X86/select-smin-smax.ll
Original file line number Diff line number Diff line change
@@ -1,66 +1,129 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-bmi < %s | FileCheck %s --check-prefixes=CHECK,CHECK-NOBMI
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi < %s | FileCheck %s --check-prefixes=CHECK,CHECK-BMI
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi < %s | FileCheck %s --check-prefixes=X64,X64-BMI
; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-bmi < %s | FileCheck %s --check-prefixes=X64,X64-NOBMI
; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,+cmov < %s | FileCheck %s --check-prefixes=X86,X86-BMI
; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=-bmi < %s | FileCheck %s --check-prefixes=X86,X86-NOBMI

declare i32 @llvm.smax.i32(i32, i32)
declare i32 @llvm.smin.i32(i32, i32)
declare i64 @llvm.smax.i64(i64, i64)
declare i64 @llvm.smin.i64(i64, i64)

define i32 @test_i32_smax(i32 %a) nounwind {
; CHECK-NOBMI-LABEL: test_i32_smax:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: xorl %eax, %eax
; CHECK-NOBMI-NEXT: testl %edi, %edi
; CHECK-NOBMI-NEXT: cmovgl %edi, %eax
; CHECK-NOBMI-NEXT: retq
; X64-BMI-LABEL: test_i32_smax:
; X64-BMI: # %bb.0:
; X64-BMI-NEXT: movl %edi, %eax
; X64-BMI-NEXT: sarl $31, %eax
; X64-BMI-NEXT: andnl %edi, %eax, %eax
; X64-BMI-NEXT: retq
;
; CHECK-BMI-LABEL: test_i32_smax:
; CHECK-BMI: # %bb.0:
; CHECK-BMI-NEXT: movl %edi, %eax
; CHECK-BMI-NEXT: sarl $31, %eax
; CHECK-BMI-NEXT: andnl %edi, %eax, %eax
; CHECK-BMI-NEXT: retq
; X64-NOBMI-LABEL: test_i32_smax:
; X64-NOBMI: # %bb.0:
; X64-NOBMI-NEXT: xorl %eax, %eax
; X64-NOBMI-NEXT: testl %edi, %edi
; X64-NOBMI-NEXT: cmovgl %edi, %eax
; X64-NOBMI-NEXT: retq
;
; X86-BMI-LABEL: test_i32_smax:
; X86-BMI: # %bb.0:
; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-BMI-NEXT: movl %eax, %ecx
; X86-BMI-NEXT: sarl $31, %ecx
; X86-BMI-NEXT: andnl %eax, %ecx, %eax
; X86-BMI-NEXT: retl
;
; X86-NOBMI-LABEL: test_i32_smax:
; X86-NOBMI: # %bb.0:
; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-NOBMI-NEXT: testl %eax, %eax
; X86-NOBMI-NEXT: jg .LBB0_2
; X86-NOBMI-NEXT: # %bb.1:
; X86-NOBMI-NEXT: xorl %eax, %eax
; X86-NOBMI-NEXT: .LBB0_2:
; X86-NOBMI-NEXT: retl
%r = call i32 @llvm.smax.i32(i32 %a, i32 0)
ret i32 %r
}

define i32 @test_i32_smin(i32 %a) nounwind {
; CHECK-LABEL: test_i32_smin:
; CHECK: # %bb.0:
; CHECK-NEXT: movl %edi, %eax
; CHECK-NEXT: sarl $31, %eax
; CHECK-NEXT: andl %edi, %eax
; CHECK-NEXT: retq
; X64-LABEL: test_i32_smin:
; X64: # %bb.0:
; X64-NEXT: movl %edi, %eax
; X64-NEXT: sarl $31, %eax
; X64-NEXT: andl %edi, %eax
; X64-NEXT: retq
;
; X86-LABEL: test_i32_smin:
; X86: # %bb.0:
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
; X86-NEXT: movl %ecx, %eax
; X86-NEXT: sarl $31, %eax
; X86-NEXT: andl %ecx, %eax
; X86-NEXT: retl
%r = call i32 @llvm.smin.i32(i32 %a, i32 0)
ret i32 %r
}

define i64 @test_i64_smax(i64 %a) nounwind {
; CHECK-NOBMI-LABEL: test_i64_smax:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: xorl %eax, %eax
; CHECK-NOBMI-NEXT: testq %rdi, %rdi
; CHECK-NOBMI-NEXT: cmovgq %rdi, %rax
; CHECK-NOBMI-NEXT: retq
; X64-BMI-LABEL: test_i64_smax:
; X64-BMI: # %bb.0:
; X64-BMI-NEXT: movq %rdi, %rax
; X64-BMI-NEXT: sarq $63, %rax
; X64-BMI-NEXT: andnq %rdi, %rax, %rax
; X64-BMI-NEXT: retq
;
; CHECK-BMI-LABEL: test_i64_smax:
; CHECK-BMI: # %bb.0:
; CHECK-BMI-NEXT: movq %rdi, %rax
; CHECK-BMI-NEXT: sarq $63, %rax
; CHECK-BMI-NEXT: andnq %rdi, %rax, %rax
; CHECK-BMI-NEXT: retq
; X64-NOBMI-LABEL: test_i64_smax:
; X64-NOBMI: # %bb.0:
; X64-NOBMI-NEXT: xorl %eax, %eax
; X64-NOBMI-NEXT: testq %rdi, %rdi
; X64-NOBMI-NEXT: cmovgq %rdi, %rax
; X64-NOBMI-NEXT: retq
;
; X86-BMI-LABEL: test_i64_smax:
; X86-BMI: # %bb.0:
; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %edx
; X86-BMI-NEXT: xorl %eax, %eax
; X86-BMI-NEXT: testl %edx, %edx
; X86-BMI-NEXT: cmovlel %eax, %edx
; X86-BMI-NEXT: cmovnsl {{[0-9]+}}(%esp), %eax
; X86-BMI-NEXT: retl
;
; X86-NOBMI-LABEL: test_i64_smax:
; X86-NOBMI: # %bb.0:
; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx
; X86-NOBMI-NEXT: testl %edx, %edx
; X86-NOBMI-NEXT: movl $0, %eax
; X86-NOBMI-NEXT: jns .LBB2_1
; X86-NOBMI-NEXT: # %bb.2:
; X86-NOBMI-NEXT: jle .LBB2_3
; X86-NOBMI-NEXT: .LBB2_4:
; X86-NOBMI-NEXT: retl
; X86-NOBMI-NEXT: .LBB2_1:
; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-NOBMI-NEXT: jg .LBB2_4
; X86-NOBMI-NEXT: .LBB2_3:
; X86-NOBMI-NEXT: xorl %edx, %edx
; X86-NOBMI-NEXT: retl
%r = call i64 @llvm.smax.i64(i64 %a, i64 0)
ret i64 %r
}

define i64 @test_i64_smin(i64 %a) nounwind {
; CHECK-LABEL: test_i64_smin:
; CHECK: # %bb.0:
; CHECK-NEXT: movq %rdi, %rax
; CHECK-NEXT: sarq $63, %rax
; CHECK-NEXT: andq %rdi, %rax
; CHECK-NEXT: retq
; X64-LABEL: test_i64_smin:
; X64: # %bb.0:
; X64-NEXT: movq %rdi, %rax
; X64-NEXT: sarq $63, %rax
; X64-NEXT: andq %rdi, %rax
; X64-NEXT: retq
;
; X86-LABEL: test_i64_smin:
; X86: # %bb.0:
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
; X86-NEXT: movl %edx, %eax
; X86-NEXT: sarl $31, %eax
; X86-NEXT: andl %eax, %edx
; X86-NEXT: andl {{[0-9]+}}(%esp), %eax
; X86-NEXT: retl
%r = call i64 @llvm.smin.i64(i64 %a, i64 0)
ret i64 %r
}