344 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi < %s | FileCheck %s --check-prefixes=X64,X64-BMI3; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=-bmi < %s | FileCheck %s --check-prefixes=X64,X64-NOBMI4; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=+bmi,+cmov < %s | FileCheck %s --check-prefixes=X86,X86-BMI5; RUN: llc -mtriple=i686-unknown-linux-gnu -mattr=-bmi < %s | FileCheck %s --check-prefixes=X86,X86-NOBMI6 7declare i8 @llvm.smax.i8(i8, i8)8declare i8 @llvm.smin.i8(i8, i8)9declare i16 @llvm.smax.i16(i16, i16)10declare i16 @llvm.smin.i16(i16, i16)11declare i32 @llvm.smax.i32(i32, i32)12declare i32 @llvm.smin.i32(i32, i32)13declare i64 @llvm.smax.i64(i64, i64)14declare i64 @llvm.smin.i64(i64, i64)15declare i128 @llvm.smax.i128(i128, i128)16declare i128 @llvm.smin.i128(i128, i128)17 18define i8 @test_i8_smax(i8 %a) nounwind {19; X64-LABEL: test_i8_smax:20; X64: # %bb.0:21; X64-NEXT: xorl %eax, %eax22; X64-NEXT: testb %dil, %dil23; X64-NEXT: cmovgl %edi, %eax24; X64-NEXT: # kill: def $al killed $al killed $eax25; X64-NEXT: retq26;27; X86-BMI-LABEL: test_i8_smax:28; X86-BMI: # %bb.0:29; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %ecx30; X86-BMI-NEXT: xorl %eax, %eax31; X86-BMI-NEXT: testb %cl, %cl32; X86-BMI-NEXT: cmovgl %ecx, %eax33; X86-BMI-NEXT: # kill: def $al killed $al killed $eax34; X86-BMI-NEXT: retl35;36; X86-NOBMI-LABEL: test_i8_smax:37; X86-NOBMI: # %bb.0:38; X86-NOBMI-NEXT: movzbl {{[0-9]+}}(%esp), %eax39; X86-NOBMI-NEXT: testb %al, %al40; X86-NOBMI-NEXT: jg .LBB0_241; X86-NOBMI-NEXT: # %bb.1:42; X86-NOBMI-NEXT: xorl %eax, %eax43; X86-NOBMI-NEXT: .LBB0_2:44; X86-NOBMI-NEXT: # kill: def $al killed $al killed $eax45; X86-NOBMI-NEXT: retl46 %r = call i8 @llvm.smax.i8(i8 %a, i8 0)47 ret i8 %r48}49 50define i8 @test_i8_smin(i8 %a) nounwind {51; X64-LABEL: test_i8_smin:52; X64: # %bb.0:53; X64-NEXT: movl %edi, %eax54; X64-NEXT: sarb $7, %al55; X64-NEXT: andb %dil, %al56; X64-NEXT: retq57;58; X86-LABEL: test_i8_smin:59; X86: # %bb.0:60; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx61; X86-NEXT: movl %ecx, %eax62; X86-NEXT: sarb $7, %al63; X86-NEXT: andb %cl, %al64; X86-NEXT: retl65 %r = call i8 @llvm.smin.i8(i8 %a, i8 0)66 ret i8 %r67}68 69define i16 @test_i16_smax(i16 %a) nounwind {70; X64-LABEL: test_i16_smax:71; X64: # %bb.0:72; X64-NEXT: xorl %eax, %eax73; X64-NEXT: testw %di, %di74; X64-NEXT: cmovgl %edi, %eax75; X64-NEXT: # kill: def $ax killed $ax killed $eax76; X64-NEXT: retq77;78; X86-BMI-LABEL: test_i16_smax:79; X86-BMI: # %bb.0:80; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %ecx81; X86-BMI-NEXT: xorl %eax, %eax82; X86-BMI-NEXT: testw %cx, %cx83; X86-BMI-NEXT: cmovgl %ecx, %eax84; X86-BMI-NEXT: # kill: def $ax killed $ax killed $eax85; X86-BMI-NEXT: retl86;87; X86-NOBMI-LABEL: test_i16_smax:88; X86-NOBMI: # %bb.0:89; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax90; X86-NOBMI-NEXT: testw %ax, %ax91; X86-NOBMI-NEXT: jg .LBB2_292; X86-NOBMI-NEXT: # %bb.1:93; X86-NOBMI-NEXT: xorl %eax, %eax94; X86-NOBMI-NEXT: .LBB2_2:95; X86-NOBMI-NEXT: # kill: def $ax killed $ax killed $eax96; X86-NOBMI-NEXT: retl97 %r = call i16 @llvm.smax.i16(i16 %a, i16 0)98 ret i16 %r99}100 101define i16 @test_i16_smin(i16 %a) nounwind {102; X64-LABEL: test_i16_smin:103; X64: # %bb.0:104; X64-NEXT: movswl %di, %eax105; X64-NEXT: sarl $15, %eax106; X64-NEXT: andl %edi, %eax107; X64-NEXT: # kill: def $ax killed $ax killed $eax108; X64-NEXT: retq109;110; X86-LABEL: test_i16_smin:111; X86: # %bb.0:112; X86-NEXT: movswl {{[0-9]+}}(%esp), %ecx113; X86-NEXT: movl %ecx, %eax114; X86-NEXT: shrl $15, %eax115; X86-NEXT: andl %ecx, %eax116; X86-NEXT: # kill: def $ax killed $ax killed $eax117; X86-NEXT: retl118 %r = call i16 @llvm.smin.i16(i16 %a, i16 0)119 ret i16 %r120}121 122define i32 @test_i32_smax(i32 %a) nounwind {123; X64-BMI-LABEL: test_i32_smax:124; X64-BMI: # %bb.0:125; X64-BMI-NEXT: movl %edi, %eax126; X64-BMI-NEXT: sarl $31, %eax127; X64-BMI-NEXT: andnl %edi, %eax, %eax128; X64-BMI-NEXT: retq129;130; X64-NOBMI-LABEL: test_i32_smax:131; X64-NOBMI: # %bb.0:132; X64-NOBMI-NEXT: xorl %eax, %eax133; X64-NOBMI-NEXT: testl %edi, %edi134; X64-NOBMI-NEXT: cmovgl %edi, %eax135; X64-NOBMI-NEXT: retq136;137; X86-BMI-LABEL: test_i32_smax:138; X86-BMI: # %bb.0:139; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %eax140; X86-BMI-NEXT: movl %eax, %ecx141; X86-BMI-NEXT: sarl $31, %ecx142; X86-BMI-NEXT: andnl %eax, %ecx, %eax143; X86-BMI-NEXT: retl144;145; X86-NOBMI-LABEL: test_i32_smax:146; X86-NOBMI: # %bb.0:147; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax148; X86-NOBMI-NEXT: testl %eax, %eax149; X86-NOBMI-NEXT: jg .LBB4_2150; X86-NOBMI-NEXT: # %bb.1:151; X86-NOBMI-NEXT: xorl %eax, %eax152; X86-NOBMI-NEXT: .LBB4_2:153; X86-NOBMI-NEXT: retl154 %r = call i32 @llvm.smax.i32(i32 %a, i32 0)155 ret i32 %r156}157 158define i32 @test_i32_smin(i32 %a) nounwind {159; X64-LABEL: test_i32_smin:160; X64: # %bb.0:161; X64-NEXT: movl %edi, %eax162; X64-NEXT: sarl $31, %eax163; X64-NEXT: andl %edi, %eax164; X64-NEXT: retq165;166; X86-LABEL: test_i32_smin:167; X86: # %bb.0:168; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx169; X86-NEXT: movl %ecx, %eax170; X86-NEXT: sarl $31, %eax171; X86-NEXT: andl %ecx, %eax172; X86-NEXT: retl173 %r = call i32 @llvm.smin.i32(i32 %a, i32 0)174 ret i32 %r175}176 177define i64 @test_i64_smax(i64 %a) nounwind {178; X64-BMI-LABEL: test_i64_smax:179; X64-BMI: # %bb.0:180; X64-BMI-NEXT: movq %rdi, %rax181; X64-BMI-NEXT: sarq $63, %rax182; X64-BMI-NEXT: andnq %rdi, %rax, %rax183; X64-BMI-NEXT: retq184;185; X64-NOBMI-LABEL: test_i64_smax:186; X64-NOBMI: # %bb.0:187; X64-NOBMI-NEXT: xorl %eax, %eax188; X64-NOBMI-NEXT: testq %rdi, %rdi189; X64-NOBMI-NEXT: cmovgq %rdi, %rax190; X64-NOBMI-NEXT: retq191;192; X86-BMI-LABEL: test_i64_smax:193; X86-BMI: # %bb.0:194; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %edx195; X86-BMI-NEXT: xorl %eax, %eax196; X86-BMI-NEXT: testl %edx, %edx197; X86-BMI-NEXT: cmovlel %eax, %edx198; X86-BMI-NEXT: cmovnsl {{[0-9]+}}(%esp), %eax199; X86-BMI-NEXT: retl200;201; X86-NOBMI-LABEL: test_i64_smax:202; X86-NOBMI: # %bb.0:203; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx204; X86-NOBMI-NEXT: testl %edx, %edx205; X86-NOBMI-NEXT: movl $0, %eax206; X86-NOBMI-NEXT: jns .LBB6_1207; X86-NOBMI-NEXT: # %bb.2:208; X86-NOBMI-NEXT: jle .LBB6_3209; X86-NOBMI-NEXT: .LBB6_4:210; X86-NOBMI-NEXT: retl211; X86-NOBMI-NEXT: .LBB6_1:212; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax213; X86-NOBMI-NEXT: jg .LBB6_4214; X86-NOBMI-NEXT: .LBB6_3:215; X86-NOBMI-NEXT: xorl %edx, %edx216; X86-NOBMI-NEXT: retl217 %r = call i64 @llvm.smax.i64(i64 %a, i64 0)218 ret i64 %r219}220 221define i64 @test_i64_smin(i64 %a) nounwind {222; X64-LABEL: test_i64_smin:223; X64: # %bb.0:224; X64-NEXT: movq %rdi, %rax225; X64-NEXT: sarq $63, %rax226; X64-NEXT: andq %rdi, %rax227; X64-NEXT: retq228;229; X86-LABEL: test_i64_smin:230; X86: # %bb.0:231; X86-NEXT: movl {{[0-9]+}}(%esp), %edx232; X86-NEXT: movl %edx, %eax233; X86-NEXT: sarl $31, %eax234; X86-NEXT: andl %eax, %edx235; X86-NEXT: andl {{[0-9]+}}(%esp), %eax236; X86-NEXT: retl237 %r = call i64 @llvm.smin.i64(i64 %a, i64 0)238 ret i64 %r239}240 241define i128 @test_i128_smax(i128 %a) nounwind {242; X64-LABEL: test_i128_smax:243; X64: # %bb.0:244; X64-NEXT: movq %rdi, %rax245; X64-NEXT: xorl %edx, %edx246; X64-NEXT: testq %rsi, %rsi247; X64-NEXT: cmovsq %rdx, %rax248; X64-NEXT: cmovgq %rsi, %rdx249; X64-NEXT: retq250;251; X86-BMI-LABEL: test_i128_smax:252; X86-BMI: # %bb.0:253; X86-BMI-NEXT: pushl %edi254; X86-BMI-NEXT: pushl %esi255; X86-BMI-NEXT: pushl %eax256; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %eax257; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %ecx258; X86-BMI-NEXT: xorl %edx, %edx259; X86-BMI-NEXT: testl %ecx, %ecx260; X86-BMI-NEXT: cmovlel %edx, %ecx261; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %esi262; X86-BMI-NEXT: cmovsl %edx, %esi263; X86-BMI-NEXT: movl {{[0-9]+}}(%esp), %edi264; X86-BMI-NEXT: cmovsl %edx, %edi265; X86-BMI-NEXT: cmovnsl {{[0-9]+}}(%esp), %edx266; X86-BMI-NEXT: movl %ecx, 12(%eax)267; X86-BMI-NEXT: movl %edx, 8(%eax)268; X86-BMI-NEXT: movl %edi, 4(%eax)269; X86-BMI-NEXT: movl %esi, (%eax)270; X86-BMI-NEXT: addl $4, %esp271; X86-BMI-NEXT: popl %esi272; X86-BMI-NEXT: popl %edi273; X86-BMI-NEXT: retl $4274;275; X86-NOBMI-LABEL: test_i128_smax:276; X86-NOBMI: # %bb.0:277; X86-NOBMI-NEXT: pushl %edi278; X86-NOBMI-NEXT: pushl %esi279; X86-NOBMI-NEXT: pushl %eax280; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %eax281; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %ecx282; X86-NOBMI-NEXT: testl %ecx, %ecx283; X86-NOBMI-NEXT: movl $0, %edx284; X86-NOBMI-NEXT: movl $0, %esi285; X86-NOBMI-NEXT: movl $0, %edi286; X86-NOBMI-NEXT: js .LBB8_2287; X86-NOBMI-NEXT: # %bb.1:288; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edi289; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %edx290; X86-NOBMI-NEXT: movl {{[0-9]+}}(%esp), %esi291; X86-NOBMI-NEXT: .LBB8_2:292; X86-NOBMI-NEXT: jg .LBB8_4293; X86-NOBMI-NEXT: # %bb.3:294; X86-NOBMI-NEXT: xorl %ecx, %ecx295; X86-NOBMI-NEXT: .LBB8_4:296; X86-NOBMI-NEXT: movl %ecx, 12(%eax)297; X86-NOBMI-NEXT: movl %edi, 8(%eax)298; X86-NOBMI-NEXT: movl %esi, 4(%eax)299; X86-NOBMI-NEXT: movl %edx, (%eax)300; X86-NOBMI-NEXT: addl $4, %esp301; X86-NOBMI-NEXT: popl %esi302; X86-NOBMI-NEXT: popl %edi303; X86-NOBMI-NEXT: retl $4304 %r = call i128 @llvm.smax.i128(i128 %a, i128 0)305 ret i128 %r306}307 308define i128 @test_i128_smin(i128 %a) nounwind {309; X64-LABEL: test_i128_smin:310; X64: # %bb.0:311; X64-NEXT: movq %rdi, %rax312; X64-NEXT: movq %rsi, %rdx313; X64-NEXT: sarq $63, %rdx314; X64-NEXT: andq %rdx, %rax315; X64-NEXT: andq %rsi, %rdx316; X64-NEXT: retq317;318; X86-LABEL: test_i128_smin:319; X86: # %bb.0:320; X86-NEXT: pushl %edi321; X86-NEXT: pushl %esi322; X86-NEXT: pushl %eax323; X86-NEXT: movl {{[0-9]+}}(%esp), %eax324; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx325; X86-NEXT: movl %ecx, %edx326; X86-NEXT: sarl $31, %edx327; X86-NEXT: andl %edx, %ecx328; X86-NEXT: movl {{[0-9]+}}(%esp), %esi329; X86-NEXT: andl %edx, %esi330; X86-NEXT: movl {{[0-9]+}}(%esp), %edi331; X86-NEXT: andl %edx, %edi332; X86-NEXT: andl {{[0-9]+}}(%esp), %edx333; X86-NEXT: movl %ecx, 12(%eax)334; X86-NEXT: movl %edx, 8(%eax)335; X86-NEXT: movl %edi, 4(%eax)336; X86-NEXT: movl %esi, (%eax)337; X86-NEXT: addl $4, %esp338; X86-NEXT: popl %esi339; X86-NEXT: popl %edi340; X86-NEXT: retl $4341 %r = call i128 @llvm.smin.i128(i128 %a, i128 0)342 ret i128 %r343}344