brintos

brintos / llvm-project-archived public Read only

0
0
Text · 14.1 KiB · 1380c02 Raw
513 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc < %s -mtriple=x86_64-unknown-unknown -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,NOBMI -enable-var-scope3; RUN: llc < %s -mtriple=x86_64-unknown-unknown -verify-machineinstrs -mattr=+bmi | FileCheck %s -check-prefixes=CHECK,BMI -enable-var-scope4 5define i32 @select_and1(i32 %x, i32 %y) {6; CHECK-LABEL: select_and1:7; CHECK:       # %bb.0:8; CHECK-NEXT:    xorl %eax, %eax9; CHECK-NEXT:    cmpl $11, %edi10; CHECK-NEXT:    cmovgel %esi, %eax11; CHECK-NEXT:    retq12  %c = icmp slt i32 %x, 1113  %s = select i1 %c, i32 0, i32 -114  %a = and i32 %y, %s15  ret i32 %a16}17 18define i32 @select_and2(i32 %x, i32 %y) {19; CHECK-LABEL: select_and2:20; CHECK:       # %bb.0:21; CHECK-NEXT:    xorl %eax, %eax22; CHECK-NEXT:    cmpl $11, %edi23; CHECK-NEXT:    cmovgel %esi, %eax24; CHECK-NEXT:    retq25  %c = icmp slt i32 %x, 1126  %s = select i1 %c, i32 0, i32 -127  %a = and i32 %s, %y28  ret i32 %a29}30 31define i32 @select_and3(i32 %x, i32 %y) {32; CHECK-LABEL: select_and3:33; CHECK:       # %bb.0:34; CHECK-NEXT:    xorl %eax, %eax35; CHECK-NEXT:    cmpl $11, %edi36; CHECK-NEXT:    cmovll %esi, %eax37; CHECK-NEXT:    retq38  %c = icmp slt i32 %x, 1139  %s = select i1 %c, i32 -1, i32 040  %a = and i32 %y, %s41  ret i32 %a42}43 44define <4 x i32> @select_and_v4(i32 %x, <4 x i32> %y) {45; CHECK-LABEL: select_and_v4:46; CHECK:       # %bb.0:47; CHECK-NEXT:    cmpl $11, %edi48; CHECK-NEXT:    xorps %xmm1, %xmm149; CHECK-NEXT:    jl .LBB3_250; CHECK-NEXT:  # %bb.1:51; CHECK-NEXT:    movaps %xmm0, %xmm152; CHECK-NEXT:  .LBB3_2:53; CHECK-NEXT:    movaps %xmm1, %xmm054; CHECK-NEXT:    retq55  %c = icmp slt i32 %x, 1156  %s = select i1 %c, <4 x i32> zeroinitializer, <4 x i32><i32 -1, i32 -1, i32 -1, i32 -1>57  %a = and <4 x i32> %s, %y58  ret <4 x i32> %a59}60 61define i32 @select_or1(i32 %x, i32 %y) {62; CHECK-LABEL: select_or1:63; CHECK:       # %bb.0:64; CHECK-NEXT:    cmpl $11, %edi65; CHECK-NEXT:    movl $-1, %eax66; CHECK-NEXT:    cmovll %esi, %eax67; CHECK-NEXT:    retq68  %c = icmp slt i32 %x, 1169  %s = select i1 %c, i32 0, i32 -170  %a = or i32 %y, %s71  ret i32 %a72}73 74define i32 @select_or2(i32 %x, i32 %y) {75; CHECK-LABEL: select_or2:76; CHECK:       # %bb.0:77; CHECK-NEXT:    cmpl $11, %edi78; CHECK-NEXT:    movl $-1, %eax79; CHECK-NEXT:    cmovll %esi, %eax80; CHECK-NEXT:    retq81  %c = icmp slt i32 %x, 1182  %s = select i1 %c, i32 0, i32 -183  %a = or i32 %s, %y84  ret i32 %a85}86 87define i32 @select_or3(i32 %x, i32 %y) {88; CHECK-LABEL: select_or3:89; CHECK:       # %bb.0:90; CHECK-NEXT:    cmpl $11, %edi91; CHECK-NEXT:    movl $-1, %eax92; CHECK-NEXT:    cmovgel %esi, %eax93; CHECK-NEXT:    retq94  %c = icmp slt i32 %x, 1195  %s = select i1 %c, i32 -1, i32 096  %a = or i32 %y, %s97  ret i32 %a98}99 100define <4 x i32> @select_or_v4(i32 %x, <4 x i32> %y) {101; CHECK-LABEL: select_or_v4:102; CHECK:       # %bb.0:103; CHECK-NEXT:    cmpl $11, %edi104; CHECK-NEXT:    jl .LBB7_2105; CHECK-NEXT:  # %bb.1:106; CHECK-NEXT:    pcmpeqd %xmm0, %xmm0107; CHECK-NEXT:  .LBB7_2:108; CHECK-NEXT:    retq109  %c = icmp slt i32 %x, 11110  %s = select i1 %c, <4 x i32> zeroinitializer, <4 x i32><i32 -1, i32 -1, i32 -1, i32 -1>111  %a = or <4 x i32> %s, %y112  ret <4 x i32> %a113}114 115define i32 @sel_constants_sub_constant_sel_constants(i1 %cond) {116; CHECK-LABEL: sel_constants_sub_constant_sel_constants:117; CHECK:       # %bb.0:118; CHECK-NEXT:    testb $1, %dil119; CHECK-NEXT:    movl $9, %ecx120; CHECK-NEXT:    movl $2, %eax121; CHECK-NEXT:    cmovnel %ecx, %eax122; CHECK-NEXT:    retq123  %sel = select i1 %cond, i32 -4, i32 3124  %bo = sub i32 5, %sel125  ret i32 %bo126}127 128define i32 @sdiv_constant_sel_constants(i1 %cond) {129; CHECK-LABEL: sdiv_constant_sel_constants:130; CHECK:       # %bb.0:131; CHECK-NEXT:    notb %dil132; CHECK-NEXT:    movzbl %dil, %eax133; CHECK-NEXT:    andl $1, %eax134; CHECK-NEXT:    leal (%rax,%rax,4), %eax135; CHECK-NEXT:    retq136  %sel = select i1 %cond, i32 121, i32 23137  %bo = sdiv i32 120, %sel138  ret i32 %bo139}140 141define i32 @udiv_constant_sel_constants(i1 %cond) {142; CHECK-LABEL: udiv_constant_sel_constants:143; CHECK:       # %bb.0:144; CHECK-NEXT:    notb %dil145; CHECK-NEXT:    movzbl %dil, %eax146; CHECK-NEXT:    andl $1, %eax147; CHECK-NEXT:    leal (%rax,%rax,4), %eax148; CHECK-NEXT:    retq149  %sel = select i1 %cond, i32 -4, i32 23150  %bo = udiv i32 120, %sel151  ret i32 %bo152}153 154define i32 @srem_constant_sel_constants(i1 %cond) {155; CHECK-LABEL: srem_constant_sel_constants:156; CHECK:       # %bb.0:157; CHECK-NEXT:    testb $1, %dil158; CHECK-NEXT:    movl $120, %ecx159; CHECK-NEXT:    movl $5, %eax160; CHECK-NEXT:    cmovnel %ecx, %eax161; CHECK-NEXT:    retq162  %sel = select i1 %cond, i32 121, i32 23163  %bo = srem i32 120, %sel164  ret i32 %bo165}166 167define i32 @urem_constant_sel_constants(i1 %cond) {168; CHECK-LABEL: urem_constant_sel_constants:169; CHECK:       # %bb.0:170; CHECK-NEXT:    testb $1, %dil171; CHECK-NEXT:    movl $120, %ecx172; CHECK-NEXT:    movl $5, %eax173; CHECK-NEXT:    cmovnel %ecx, %eax174; CHECK-NEXT:    retq175  %sel = select i1 %cond, i32 -4, i32 23176  %bo = urem i32 120, %sel177  ret i32 %bo178}179 180define i32 @sel_constants_shl_constant(i1 %cond) {181; CHECK-LABEL: sel_constants_shl_constant:182; CHECK:       # %bb.0:183; CHECK-NEXT:    notb %dil184; CHECK-NEXT:    movzbl %dil, %eax185; CHECK-NEXT:    andl $1, %eax186; CHECK-NEXT:    orl $2, %eax187; CHECK-NEXT:    shll $8, %eax188; CHECK-NEXT:    retq189  %sel = select i1 %cond, i32 2, i32 3190  %bo = shl i32 %sel, 8191  ret i32 %bo192}193 194define i32 @shl_constant_sel_constants(i1 %cond) {195; CHECK-LABEL: shl_constant_sel_constants:196; CHECK:       # %bb.0:197; CHECK-NEXT:    notb %dil198; CHECK-NEXT:    movzbl %dil, %eax199; CHECK-NEXT:    andl $1, %eax200; CHECK-NEXT:    leal 4(,%rax,4), %eax201; CHECK-NEXT:    retq202  %sel = select i1 %cond, i32 2, i32 3203  %bo = shl i32 1, %sel204  ret i32 %bo205}206 207define i32 @shl_constant_sel_setcc(i32 %a) {208; CHECK-LABEL: shl_constant_sel_setcc:209; CHECK:       # %bb.0:210; CHECK-NEXT:    xorl %eax, %eax211; CHECK-NEXT:    testb $1, %dil212; CHECK-NEXT:    sete %al213; CHECK-NEXT:    leal 4(,%rax,4), %eax214; CHECK-NEXT:    retq215  %m = and i32 %a, 1216  %cond = icmp ne i32 %m, 0217  %sel = select i1 %cond, i32 2, i32 3218  %bo = shl i32 1, %sel219  ret i32 %bo220}221 222define i32 @lshr_constant_sel_constants(i1 %cond) {223; CHECK-LABEL: lshr_constant_sel_constants:224; CHECK:       # %bb.0:225; CHECK-NEXT:    # kill: def $edi killed $edi def $rdi226; CHECK-NEXT:    andl $1, %edi227; CHECK-NEXT:    leal 8(,%rdi,8), %eax228; CHECK-NEXT:    retq229  %sel = select i1 %cond, i32 2, i32 3230  %bo = lshr i32 64, %sel231  ret i32 %bo232}233 234define i32 @lshr_constant_sel_setcc(i32 %a) {235; CHECK-LABEL: lshr_constant_sel_setcc:236; CHECK:       # %bb.0:237; CHECK-NEXT:    # kill: def $edi killed $edi def $rdi238; CHECK-NEXT:    andl $1, %edi239; CHECK-NEXT:    leal 8(,%rdi,8), %eax240; CHECK-NEXT:    retq241  %m = and i32 %a, 1242  %cond = icmp ne i32 %m, 0243  %sel = select i1 %cond, i32 2, i32 3244  %bo = lshr i32 64, %sel245  ret i32 %bo246}247 248define i32 @ashr_constant_sel_constants(i1 %cond) {249; CHECK-LABEL: ashr_constant_sel_constants:250; CHECK:       # %bb.0:251; CHECK-NEXT:    # kill: def $edi killed $edi def $rdi252; CHECK-NEXT:    andl $1, %edi253; CHECK-NEXT:    shll $4, %edi254; CHECK-NEXT:    leal 16(%rdi), %eax255; CHECK-NEXT:    retq256  %sel = select i1 %cond, i32 2, i32 3257  %bo = ashr i32 128, %sel258  ret i32 %bo259}260 261define i32 @ashr_constant_sel_setcc(i32 %a) {262; CHECK-LABEL: ashr_constant_sel_setcc:263; CHECK:       # %bb.0:264; CHECK-NEXT:    # kill: def $edi killed $edi def $rdi265; CHECK-NEXT:    andl $1, %edi266; CHECK-NEXT:    shll $4, %edi267; CHECK-NEXT:    leal 16(%rdi), %eax268; CHECK-NEXT:    retq269  %m = and i32 %a, 1270  %cond = icmp ne i32 %m, 0271  %sel = select i1 %cond, i32 2, i32 3272  %bo = ashr i32 128, %sel273  ret i32 %bo274}275 276define double @fsub_constant_sel_constants(i1 %cond) {277; CHECK-LABEL: fsub_constant_sel_constants:278; CHECK:       # %bb.0:279; CHECK-NEXT:    testb $1, %dil280; CHECK-NEXT:    jne .LBB20_1281; CHECK-NEXT:  # %bb.2:282; CHECK-NEXT:    movsd {{.*#+}} xmm0 = [-1.8200000000000003E+1,0.0E+0]283; CHECK-NEXT:    retq284; CHECK-NEXT:  .LBB20_1:285; CHECK-NEXT:    movsd {{.*#+}} xmm0 = [9.0999999999999996E+0,0.0E+0]286; CHECK-NEXT:    retq287  %sel = select i1 %cond, double -4.0, double 23.3288  %bo = fsub double 5.1, %sel289  ret double %bo290}291 292define double @fdiv_constant_sel_constants(i1 %cond) {293; CHECK-LABEL: fdiv_constant_sel_constants:294; CHECK:       # %bb.0:295; CHECK-NEXT:    testb $1, %dil296; CHECK-NEXT:    jne .LBB21_1297; CHECK-NEXT:  # %bb.2:298; CHECK-NEXT:    movsd {{.*#+}} xmm0 = [2.188841201716738E-1,0.0E+0]299; CHECK-NEXT:    retq300; CHECK-NEXT:  .LBB21_1:301; CHECK-NEXT:    movsd {{.*#+}} xmm0 = [-1.2749999999999999E+0,0.0E+0]302; CHECK-NEXT:    retq303  %sel = select i1 %cond, double -4.0, double 23.3304  %bo = fdiv double 5.1, %sel305  ret double %bo306}307 308define double @frem_constant_sel_constants(i1 %cond) {309; CHECK-LABEL: frem_constant_sel_constants:310; CHECK:       # %bb.0:311; CHECK-NEXT:    testb $1, %dil312; CHECK-NEXT:    jne .LBB22_1313; CHECK-NEXT:  # %bb.2:314; CHECK-NEXT:    movsd {{.*#+}} xmm0 = [5.0999999999999996E+0,0.0E+0]315; CHECK-NEXT:    retq316; CHECK-NEXT:  .LBB22_1:317; CHECK-NEXT:    movsd {{.*#+}} xmm0 = [1.0999999999999996E+0,0.0E+0]318; CHECK-NEXT:    retq319  %sel = select i1 %cond, double -4.0, double 23.3320  %bo = frem double 5.1, %sel321  ret double %bo322}323 324declare i64 @llvm.cttz.i64(i64, i1)325define i64 @cttz_64_eq_select(i64 %v) nounwind {326; NOBMI-LABEL: cttz_64_eq_select:327; NOBMI:       # %bb.0:328; NOBMI-NEXT:    bsfq %rdi, %rcx329; NOBMI-NEXT:    movq $-1, %rax330; NOBMI-NEXT:    cmovneq %rcx, %rax331; NOBMI-NEXT:    addq $6, %rax332; NOBMI-NEXT:    retq333;334; BMI-LABEL: cttz_64_eq_select:335; BMI:       # %bb.0:336; BMI-NEXT:    tzcntq %rdi, %rcx337; BMI-NEXT:    movq $-1, %rax338; BMI-NEXT:    cmovaeq %rcx, %rax339; BMI-NEXT:    addq $6, %rax340; BMI-NEXT:    retq341 342  %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)343  %tobool = icmp eq i64 %v, 0344  %.op = add nuw nsw i64 %cnt, 6345  %add = select i1 %tobool, i64 5, i64 %.op346  ret i64 %add347}348 349define i64 @cttz_64_ne_select(i64 %v) nounwind {350; NOBMI-LABEL: cttz_64_ne_select:351; NOBMI:       # %bb.0:352; NOBMI-NEXT:    bsfq %rdi, %rcx353; NOBMI-NEXT:    movq $-1, %rax354; NOBMI-NEXT:    cmovneq %rcx, %rax355; NOBMI-NEXT:    addq $6, %rax356; NOBMI-NEXT:    retq357;358; BMI-LABEL: cttz_64_ne_select:359; BMI:       # %bb.0:360; BMI-NEXT:    tzcntq %rdi, %rcx361; BMI-NEXT:    movq $-1, %rax362; BMI-NEXT:    cmovaeq %rcx, %rax363; BMI-NEXT:    addq $6, %rax364; BMI-NEXT:    retq365 366  %cnt = tail call i64 @llvm.cttz.i64(i64 %v, i1 true)367  %tobool = icmp ne i64 %v, 0368  %.op = add nuw nsw i64 %cnt, 6369  %add = select i1 %tobool, i64 %.op, i64 5370  ret i64 %add371}372 373declare i32 @llvm.cttz.i32(i32, i1)374define i32 @cttz_32_eq_select(i32 %v) nounwind {375; NOBMI-LABEL: cttz_32_eq_select:376; NOBMI:       # %bb.0:377; NOBMI-NEXT:    bsfl %edi, %ecx378; NOBMI-NEXT:    movl $-1, %eax379; NOBMI-NEXT:    cmovnel %ecx, %eax380; NOBMI-NEXT:    addl $6, %eax381; NOBMI-NEXT:    retq382;383; BMI-LABEL: cttz_32_eq_select:384; BMI:       # %bb.0:385; BMI-NEXT:    tzcntl %edi, %ecx386; BMI-NEXT:    movl $-1, %eax387; BMI-NEXT:    cmovael %ecx, %eax388; BMI-NEXT:    addl $6, %eax389; BMI-NEXT:    retq390 391  %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)392  %tobool = icmp eq i32 %v, 0393  %.op = add nuw nsw i32 %cnt, 6394  %add = select i1 %tobool, i32 5, i32 %.op395  ret i32 %add396}397 398define i32 @cttz_32_ne_select(i32 %v) nounwind {399; NOBMI-LABEL: cttz_32_ne_select:400; NOBMI:       # %bb.0:401; NOBMI-NEXT:    bsfl %edi, %ecx402; NOBMI-NEXT:    movl $-1, %eax403; NOBMI-NEXT:    cmovnel %ecx, %eax404; NOBMI-NEXT:    addl $6, %eax405; NOBMI-NEXT:    retq406;407; BMI-LABEL: cttz_32_ne_select:408; BMI:       # %bb.0:409; BMI-NEXT:    tzcntl %edi, %ecx410; BMI-NEXT:    movl $-1, %eax411; BMI-NEXT:    cmovael %ecx, %eax412; BMI-NEXT:    addl $6, %eax413; BMI-NEXT:    retq414 415  %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)416  %tobool = icmp ne i32 %v, 0417  %.op = add nuw nsw i32 %cnt, 6418  %add = select i1 %tobool, i32 %.op, i32 5419  ret i32 %add420}421 422; This matches the pattern emitted for __builtin_ffs423define i32 @cttz_32_eq_select_ffs(i32 %v) nounwind {424; NOBMI-LABEL: cttz_32_eq_select_ffs:425; NOBMI:       # %bb.0:426; NOBMI-NEXT:    bsfl %edi, %ecx427; NOBMI-NEXT:    movl $-1, %eax428; NOBMI-NEXT:    cmovnel %ecx, %eax429; NOBMI-NEXT:    incl %eax430; NOBMI-NEXT:    retq431;432; BMI-LABEL: cttz_32_eq_select_ffs:433; BMI:       # %bb.0:434; BMI-NEXT:    tzcntl %edi, %ecx435; BMI-NEXT:    movl $-1, %eax436; BMI-NEXT:    cmovael %ecx, %eax437; BMI-NEXT:    incl %eax438; BMI-NEXT:    retq439 440  %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)441  %tobool = icmp eq i32 %v, 0442  %.op = add nuw nsw i32 %cnt, 1443  %add = select i1 %tobool, i32 0, i32 %.op444  ret i32 %add445}446 447define i32 @cttz_32_ne_select_ffs(i32 %v) nounwind {448; NOBMI-LABEL: cttz_32_ne_select_ffs:449; NOBMI:       # %bb.0:450; NOBMI-NEXT:    bsfl %edi, %ecx451; NOBMI-NEXT:    movl $-1, %eax452; NOBMI-NEXT:    cmovnel %ecx, %eax453; NOBMI-NEXT:    incl %eax454; NOBMI-NEXT:    retq455;456; BMI-LABEL: cttz_32_ne_select_ffs:457; BMI:       # %bb.0:458; BMI-NEXT:    tzcntl %edi, %ecx459; BMI-NEXT:    movl $-1, %eax460; BMI-NEXT:    cmovael %ecx, %eax461; BMI-NEXT:    incl %eax462; BMI-NEXT:    retq463 464  %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)465  %tobool = icmp ne i32 %v, 0466  %.op = add nuw nsw i32 %cnt, 1467  %add = select i1 %tobool, i32 %.op, i32 0468  ret i32 %add469}470 471; This matches the pattern emitted for __builtin_ffs - 1472define i32 @cttz_32_eq_select_ffs_m1(i32 %v) nounwind {473; NOBMI-LABEL: cttz_32_eq_select_ffs_m1:474; NOBMI:       # %bb.0:475; NOBMI-NEXT:    bsfl %edi, %ecx476; NOBMI-NEXT:    movl $-1, %eax477; NOBMI-NEXT:    cmovnel %ecx, %eax478; NOBMI-NEXT:    retq479;480; BMI-LABEL: cttz_32_eq_select_ffs_m1:481; BMI:       # %bb.0:482; BMI-NEXT:    tzcntl %edi, %ecx483; BMI-NEXT:    movl $-1, %eax484; BMI-NEXT:    cmovael %ecx, %eax485; BMI-NEXT:    retq486 487  %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)488  %tobool = icmp eq i32 %v, 0489  %sel = select i1 %tobool, i32 -1, i32 %cnt490  ret i32 %sel491}492 493define i32 @cttz_32_ne_select_ffs_m1(i32 %v) nounwind {494; NOBMI-LABEL: cttz_32_ne_select_ffs_m1:495; NOBMI:       # %bb.0:496; NOBMI-NEXT:    bsfl %edi, %ecx497; NOBMI-NEXT:    movl $-1, %eax498; NOBMI-NEXT:    cmovnel %ecx, %eax499; NOBMI-NEXT:    retq500;501; BMI-LABEL: cttz_32_ne_select_ffs_m1:502; BMI:       # %bb.0:503; BMI-NEXT:    tzcntl %edi, %ecx504; BMI-NEXT:    movl $-1, %eax505; BMI-NEXT:    cmovael %ecx, %eax506; BMI-NEXT:    retq507 508  %cnt = tail call i32 @llvm.cttz.i32(i32 %v, i1 true)509  %tobool = icmp ne i32 %v, 0510  %sel = select i1 %tobool, i32 %cnt, i32 -1511  ret i32 %sel512}513