242 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=ANY,CHECK-NOBMI3; RUN: llc -mtriple=x86_64-unknown-linux-gnu -mattr=+bmi < %s | FileCheck %s --check-prefixes=ANY,CHECK-BMI4 5; Compare if negative and select of constants where one constant is zero.6 7define i32 @neg_sel_constants(i32 %a) {8; ANY-LABEL: neg_sel_constants:9; ANY: # %bb.0:10; ANY-NEXT: movl %edi, %eax11; ANY-NEXT: sarl $31, %eax12; ANY-NEXT: andl $5, %eax13; ANY-NEXT: retq14 %tmp.1 = icmp slt i32 %a, 015 %retval = select i1 %tmp.1, i32 5, i32 016 ret i32 %retval17}18 19; Compare if negative and select of constants where one constant is zero and the other is a single bit.20 21define i32 @neg_sel_special_constant(i32 %a) {22; ANY-LABEL: neg_sel_special_constant:23; ANY: # %bb.0:24; ANY-NEXT: movl %edi, %eax25; ANY-NEXT: shrl $22, %eax26; ANY-NEXT: andl $512, %eax # imm = 0x20027; ANY-NEXT: retq28 %tmp.1 = icmp slt i32 %a, 029 %retval = select i1 %tmp.1, i32 512, i32 030 ret i32 %retval31}32 33; Compare if negative and select variable or zero.34 35define i32 @neg_sel_variable_and_zero(i32 %a, i32 %b) {36; ANY-LABEL: neg_sel_variable_and_zero:37; ANY: # %bb.0:38; ANY-NEXT: movl %edi, %eax39; ANY-NEXT: sarl $31, %eax40; ANY-NEXT: andl %esi, %eax41; ANY-NEXT: retq42 %tmp.1 = icmp slt i32 %a, 043 %retval = select i1 %tmp.1, i32 %b, i32 044 ret i32 %retval45}46 47; Compare if not positive and select the same variable as being compared: smin(a, 0).48 49define i32 @not_pos_sel_same_variable(i32 %a) {50; ANY-LABEL: not_pos_sel_same_variable:51; ANY: # %bb.0:52; ANY-NEXT: movl %edi, %eax53; ANY-NEXT: sarl $31, %eax54; ANY-NEXT: andl %edi, %eax55; ANY-NEXT: retq56 %tmp = icmp slt i32 %a, 157 %min = select i1 %tmp, i32 %a, i32 058 ret i32 %min59}60 61; Flipping the comparison condition can be handled by getting the bitwise not of the sign mask.62 63; Compare if positive and select of constants where one constant is zero.64 65define i32 @pos_sel_constants(i32 %a) {66; ANY-LABEL: pos_sel_constants:67; ANY: # %bb.0:68; ANY-NEXT: # kill: def $edi killed $edi def $rdi69; ANY-NEXT: notl %edi70; ANY-NEXT: shrl $31, %edi71; ANY-NEXT: leal (%rdi,%rdi,4), %eax72; ANY-NEXT: retq73 %tmp.1 = icmp sgt i32 %a, -174 %retval = select i1 %tmp.1, i32 5, i32 075 ret i32 %retval76}77 78; Compare if positive and select of constants where one constant is zero and the other is a single bit.79 80define i32 @pos_sel_special_constant(i32 %a) {81; ANY-LABEL: pos_sel_special_constant:82; ANY: # %bb.0:83; ANY-NEXT: movl %edi, %eax84; ANY-NEXT: notl %eax85; ANY-NEXT: shrl $22, %eax86; ANY-NEXT: andl $512, %eax # imm = 0x20087; ANY-NEXT: retq88 %tmp.1 = icmp sgt i32 %a, -189 %retval = select i1 %tmp.1, i32 512, i32 090 ret i32 %retval91}92 93; Compare if positive and select variable or zero.94 95define i32 @pos_sel_variable_and_zero(i32 %a, i32 %b) {96; CHECK-NOBMI-LABEL: pos_sel_variable_and_zero:97; CHECK-NOBMI: # %bb.0:98; CHECK-NOBMI-NEXT: xorl %eax, %eax99; CHECK-NOBMI-NEXT: testl %edi, %edi100; CHECK-NOBMI-NEXT: cmovnsl %esi, %eax101; CHECK-NOBMI-NEXT: retq102;103; CHECK-BMI-LABEL: pos_sel_variable_and_zero:104; CHECK-BMI: # %bb.0:105; CHECK-BMI-NEXT: sarl $31, %edi106; CHECK-BMI-NEXT: andnl %esi, %edi, %eax107; CHECK-BMI-NEXT: retq108 %tmp.1 = icmp sgt i32 %a, -1109 %retval = select i1 %tmp.1, i32 %b, i32 0110 ret i32 %retval111}112 113; Compare if not negative or zero and select the same variable as being compared: smax(a, 0).114 115define i32 @not_neg_sel_same_variable(i32 %a) {116; CHECK-NOBMI-LABEL: not_neg_sel_same_variable:117; CHECK-NOBMI: # %bb.0:118; CHECK-NOBMI-NEXT: xorl %eax, %eax119; CHECK-NOBMI-NEXT: testl %edi, %edi120; CHECK-NOBMI-NEXT: cmovnsl %edi, %eax121; CHECK-NOBMI-NEXT: retq122;123; CHECK-BMI-LABEL: not_neg_sel_same_variable:124; CHECK-BMI: # %bb.0:125; CHECK-BMI-NEXT: movl %edi, %eax126; CHECK-BMI-NEXT: sarl $31, %eax127; CHECK-BMI-NEXT: andnl %edi, %eax, %eax128; CHECK-BMI-NEXT: retq129 %tmp = icmp sgt i32 %a, 0130 %min = select i1 %tmp, i32 %a, i32 0131 ret i32 %min132}133 134; https://llvm.org/bugs/show_bug.cgi?id=31175135 136; ret = (x-y) > 0 ? x-y : 0137define i32 @PR31175(i32 %x, i32 %y) {138; CHECK-NOBMI-LABEL: PR31175:139; CHECK-NOBMI: # %bb.0:140; CHECK-NOBMI-NEXT: xorl %eax, %eax141; CHECK-NOBMI-NEXT: subl %esi, %edi142; CHECK-NOBMI-NEXT: cmovnsl %edi, %eax143; CHECK-NOBMI-NEXT: retq144;145; CHECK-BMI-LABEL: PR31175:146; CHECK-BMI: # %bb.0:147; CHECK-BMI-NEXT: subl %esi, %edi148; CHECK-BMI-NEXT: movl %edi, %eax149; CHECK-BMI-NEXT: sarl $31, %eax150; CHECK-BMI-NEXT: andnl %edi, %eax, %eax151; CHECK-BMI-NEXT: retq152 %sub = sub nsw i32 %x, %y153 %cmp = icmp sgt i32 %sub, 0154 %sel = select i1 %cmp, i32 %sub, i32 0155 ret i32 %sel156}157 158define i8 @sel_shift_bool_i8(i1 %t) {159; ANY-LABEL: sel_shift_bool_i8:160; ANY: # %bb.0:161; ANY-NEXT: movl %edi, %eax162; ANY-NEXT: shlb $7, %al163; ANY-NEXT: # kill: def $al killed $al killed $eax164; ANY-NEXT: retq165 %shl = select i1 %t, i8 128, i8 0166 ret i8 %shl167}168 169define i16 @sel_shift_bool_i16(i1 %t) {170; ANY-LABEL: sel_shift_bool_i16:171; ANY: # %bb.0:172; ANY-NEXT: movl %edi, %eax173; ANY-NEXT: andl $1, %eax174; ANY-NEXT: shll $7, %eax175; ANY-NEXT: # kill: def $ax killed $ax killed $eax176; ANY-NEXT: retq177 %shl = select i1 %t, i16 128, i16 0178 ret i16 %shl179}180 181define i32 @sel_shift_bool_i32(i1 %t) {182; ANY-LABEL: sel_shift_bool_i32:183; ANY: # %bb.0:184; ANY-NEXT: movl %edi, %eax185; ANY-NEXT: andl $1, %eax186; ANY-NEXT: shll $6, %eax187; ANY-NEXT: retq188 %shl = select i1 %t, i32 64, i32 0189 ret i32 %shl190}191 192define i64 @sel_shift_bool_i64(i1 %t) {193; ANY-LABEL: sel_shift_bool_i64:194; ANY: # %bb.0:195; ANY-NEXT: movl %edi, %eax196; ANY-NEXT: andl $1, %eax197; ANY-NEXT: shll $16, %eax198; ANY-NEXT: retq199 %shl = select i1 %t, i64 65536, i64 0200 ret i64 %shl201}202 203define <16 x i8> @sel_shift_bool_v16i8(<16 x i1> %t) {204; ANY-LABEL: sel_shift_bool_v16i8:205; ANY: # %bb.0:206; ANY-NEXT: psllw $7, %xmm0207; ANY-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0208; ANY-NEXT: retq209 %shl = select <16 x i1> %t, <16 x i8> <i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128, i8 128>, <16 x i8> zeroinitializer210 ret <16 x i8> %shl211}212 213define <8 x i16> @sel_shift_bool_v8i16(<8 x i1> %t) {214; ANY-LABEL: sel_shift_bool_v8i16:215; ANY: # %bb.0:216; ANY-NEXT: psllw $7, %xmm0217; ANY-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0218; ANY-NEXT: retq219 %shl= select <8 x i1> %t, <8 x i16> <i16 128, i16 128, i16 128, i16 128, i16 128, i16 128, i16 128, i16 128>, <8 x i16> zeroinitializer220 ret <8 x i16> %shl221}222 223define <4 x i32> @sel_shift_bool_v4i32(<4 x i1> %t) {224; ANY-LABEL: sel_shift_bool_v4i32:225; ANY: # %bb.0:226; ANY-NEXT: pslld $6, %xmm0227; ANY-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0228; ANY-NEXT: retq229 %shl = select <4 x i1> %t, <4 x i32> <i32 64, i32 64, i32 64, i32 64>, <4 x i32> zeroinitializer230 ret <4 x i32> %shl231}232 233define <2 x i64> @sel_shift_bool_v2i64(<2 x i1> %t) {234; ANY-LABEL: sel_shift_bool_v2i64:235; ANY: # %bb.0:236; ANY-NEXT: psllq $16, %xmm0237; ANY-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0238; ANY-NEXT: retq239 %shl = select <2 x i1> %t, <2 x i64> <i64 65536, i64 65536>, <2 x i64> zeroinitializer240 ret <2 x i64> %shl241}242