151 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mcpu=x86-64 | FileCheck %s3 4; More than one 'arcp' division using a single divisor operand5; should be converted into a reciprocal and multiplication.6 7; Don't do anything for just one division.8 9define float @div1_arcp(float %x, float %y, float %z) {10; CHECK-LABEL: div1_arcp:11; CHECK: # %bb.0:12; CHECK-NEXT: divss %xmm1, %xmm013; CHECK-NEXT: retq14 %div1 = fdiv arcp float %x, %y15 ret float %div116}17 18; All math instructions are 'arcp', so optimize.19 20define float @div2_arcp_all(float %x, float %y, float %z) {21; CHECK-LABEL: div2_arcp_all:22; CHECK: # %bb.0:23; CHECK-NEXT: movss {{.*#+}} xmm3 = [1.0E+0,0.0E+0,0.0E+0,0.0E+0]24; CHECK-NEXT: divss %xmm2, %xmm325; CHECK-NEXT: mulss %xmm3, %xmm026; CHECK-NEXT: mulss %xmm1, %xmm027; CHECK-NEXT: mulss %xmm3, %xmm028; CHECK-NEXT: retq29 %div1 = fdiv arcp float %x, %z30 %mul = fmul arcp float %div1, %y31 %div2 = fdiv arcp float %mul, %z32 ret float %div233}34 35; The first division is not 'arcp', so do not optimize.36 37define float @div2_arcp_partial1(float %x, float %y, float %z) {38; CHECK-LABEL: div2_arcp_partial1:39; CHECK: # %bb.0:40; CHECK-NEXT: divss %xmm2, %xmm041; CHECK-NEXT: mulss %xmm1, %xmm042; CHECK-NEXT: divss %xmm2, %xmm043; CHECK-NEXT: retq44 %div1 = fdiv float %x, %z45 %mul = fmul arcp float %div1, %y46 %div2 = fdiv arcp float %mul, %z47 ret float %div248}49 50; The second division is not 'arcp', so do not optimize.51 52define float @div2_arcp_partial2(float %x, float %y, float %z) {53; CHECK-LABEL: div2_arcp_partial2:54; CHECK: # %bb.0:55; CHECK-NEXT: divss %xmm2, %xmm056; CHECK-NEXT: mulss %xmm1, %xmm057; CHECK-NEXT: divss %xmm2, %xmm058; CHECK-NEXT: retq59 %div1 = fdiv arcp float %x, %z60 %mul = fmul arcp float %div1, %y61 %div2 = fdiv float %mul, %z62 ret float %div263}64 65; The multiply is not 'arcp', but that does not prevent optimizing the divisions.66 67define float @div2_arcp_partial3(float %x, float %y, float %z) {68; CHECK-LABEL: div2_arcp_partial3:69; CHECK: # %bb.0:70; CHECK-NEXT: movss {{.*#+}} xmm3 = [1.0E+0,0.0E+0,0.0E+0,0.0E+0]71; CHECK-NEXT: divss %xmm2, %xmm372; CHECK-NEXT: mulss %xmm3, %xmm073; CHECK-NEXT: mulss %xmm1, %xmm074; CHECK-NEXT: mulss %xmm3, %xmm075; CHECK-NEXT: retq76 %div1 = fdiv arcp float %x, %z77 %mul = fmul float %div1, %y78 %div2 = fdiv arcp float %mul, %z79 ret float %div280}81 82; If the reciprocal is already calculated, we should not83; generate an extra multiplication by 1.0.84 85define double @div3_arcp(double %x, double %y, double %z) {86; CHECK-LABEL: div3_arcp:87; CHECK: # %bb.0:88; CHECK-NEXT: movsd {{.*#+}} xmm2 = [1.0E+0,0.0E+0]89; CHECK-NEXT: divsd %xmm1, %xmm290; CHECK-NEXT: mulsd %xmm2, %xmm091; CHECK-NEXT: addsd %xmm2, %xmm092; CHECK-NEXT: retq93 %div1 = fdiv fast double 1.0, %y94 %div2 = fdiv fast double %x, %y95 %ret = fadd fast double %div2, %div196 ret double %ret97}98 99define float @div_select_constant_fold(i1 zeroext %arg) {100; CHECK-LABEL: div_select_constant_fold:101; CHECK: # %bb.0:102; CHECK-NEXT: testl %edi, %edi103; CHECK-NEXT: jne .LBB6_1104; CHECK-NEXT: # %bb.2:105; CHECK-NEXT: movss {{.*#+}} xmm0 = [3.0E+0,0.0E+0,0.0E+0,0.0E+0]106; CHECK-NEXT: retq107; CHECK-NEXT: .LBB6_1:108; CHECK-NEXT: movss {{.*#+}} xmm0 = [2.5E+0,0.0E+0,0.0E+0,0.0E+0]109; CHECK-NEXT: retq110 %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00111 %B2 = fdiv nnan float %tmp, 2.000000e+00112 ret float %B2113}114 115define float @div_select_constant_fold_zero(i1 zeroext %arg) {116; CHECK-LABEL: div_select_constant_fold_zero:117; CHECK: # %bb.0:118; CHECK-NEXT: movss {{.*#+}} xmm0 = [+Inf,0.0E+0,0.0E+0,0.0E+0]119; CHECK-NEXT: retq120 %tmp = select i1 %arg, float 5.000000e+00, float 6.000000e+00121 %B2 = fdiv float %tmp, 0.000000e+00122 ret float %B2123}124 125define void @PR24141() {126; CHECK-LABEL: PR24141:127; CHECK: # %bb.0: # %entry128; CHECK-NEXT: pushq %rax129; CHECK-NEXT: .cfi_def_cfa_offset 16130; CHECK-NEXT: # implicit-def: $xmm0131; CHECK-NEXT: .p2align 4132; CHECK-NEXT: .LBB8_1: # %while.body133; CHECK-NEXT: # =>This Inner Loop Header: Depth=1134; CHECK-NEXT: callq g@PLT135; CHECK-NEXT: divsd %xmm1, %xmm0136; CHECK-NEXT: jmp .LBB8_1137entry:138 br label %while.body139 140while.body:141 %x.0 = phi double [ undef, %entry ], [ %div, %while.body ]142 %call = call { double, double } @g(double %x.0)143 %xv0 = extractvalue { double, double } %call, 0144 %xv1 = extractvalue { double, double } %call, 1145 %div = fdiv arcp double %xv0, %xv1146 br label %while.body147}148 149declare { double, double } @g(double)150 151