Home | History | Annotate | Download | only in BBVectorize
      1 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
      2 ; RUN: opt < %s -bb-vectorize -bb-vectorize-req-chain-depth=3 -bb-vectorize-ignore-target-info -instcombine -gvn -S | FileCheck %s
      3 
      4 declare double @llvm.fma.f64(double, double, double)
      5 declare double @llvm.fmuladd.f64(double, double, double)
      6 declare double @llvm.cos.f64(double)
      7 declare double @llvm.powi.f64(double, i32)
      8 
      9 ; Basic depth-3 chain with fma
     10 define double @test1(double %A1, double %A2, double %B1, double %B2, double %C1, double %C2) {
     11 	%X1 = fsub double %A1, %B1
     12 	%X2 = fsub double %A2, %B2
     13 	%Y1 = call double @llvm.fma.f64(double %X1, double %A1, double %C1)
     14 	%Y2 = call double @llvm.fma.f64(double %X2, double %A2, double %C2)
     15 	%Z1 = fadd double %Y1, %B1
     16 	%Z2 = fadd double %Y2, %B2
     17 	%R  = fmul double %Z1, %Z2
     18 	ret double %R
     19 ; CHECK: @test1
     20 ; CHECK: %X1.v.i1.1 = insertelement <2 x double> undef, double %B1, i32 0
     21 ; CHECK: %X1.v.i1.2 = insertelement <2 x double> %X1.v.i1.1, double %B2, i32 1
     22 ; CHECK: %X1.v.i0.1 = insertelement <2 x double> undef, double %A1, i32 0
     23 ; CHECK: %X1.v.i0.2 = insertelement <2 x double> %X1.v.i0.1, double %A2, i32 1
     24 ; CHECK: %X1 = fsub <2 x double> %X1.v.i0.2, %X1.v.i1.2
     25 ; CHECK: %Y1.v.i2.1 = insertelement <2 x double> undef, double %C1, i32 0
     26 ; CHECK: %Y1.v.i2.2 = insertelement <2 x double> %Y1.v.i2.1, double %C2, i32 1
     27 ; CHECK: %Y1 = call <2 x double> @llvm.fma.v2f64(<2 x double> %X1, <2 x double> %X1.v.i0.2, <2 x double> %Y1.v.i2.2)
     28 ; CHECK: %Z1 = fadd <2 x double> %Y1, %X1.v.i1.2
     29 ; CHECK: %Z1.v.r1 = extractelement <2 x double> %Z1, i32 0
     30 ; CHECK: %Z1.v.r2 = extractelement <2 x double> %Z1, i32 1
     31 ; CHECK: %R = fmul double %Z1.v.r1, %Z1.v.r2
     32 ; CHECK: ret double %R
     33 }
     34 
     35 ; Basic depth-3 chain with fmuladd
     36 define double @test1a(double %A1, double %A2, double %B1, double %B2, double %C1, double %C2) {
     37 	%X1 = fsub double %A1, %B1
     38 	%X2 = fsub double %A2, %B2
     39 	%Y1 = call double @llvm.fmuladd.f64(double %X1, double %A1, double %C1)
     40 	%Y2 = call double @llvm.fmuladd.f64(double %X2, double %A2, double %C2)
     41 	%Z1 = fadd double %Y1, %B1
     42 	%Z2 = fadd double %Y2, %B2
     43 	%R  = fmul double %Z1, %Z2
     44 	ret double %R
     45 ; CHECK: @test1a
     46 ; CHECK: %X1.v.i1.1 = insertelement <2 x double> undef, double %B1, i32 0
     47 ; CHECK: %X1.v.i1.2 = insertelement <2 x double> %X1.v.i1.1, double %B2, i32 1
     48 ; CHECK: %X1.v.i0.1 = insertelement <2 x double> undef, double %A1, i32 0
     49 ; CHECK: %X1.v.i0.2 = insertelement <2 x double> %X1.v.i0.1, double %A2, i32 1
     50 ; CHECK: %X1 = fsub <2 x double> %X1.v.i0.2, %X1.v.i1.2
     51 ; CHECK: %Y1.v.i2.1 = insertelement <2 x double> undef, double %C1, i32 0
     52 ; CHECK: %Y1.v.i2.2 = insertelement <2 x double> %Y1.v.i2.1, double %C2, i32 1
     53 ; CHECK: %Y1 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %X1, <2 x double> %X1.v.i0.2, <2 x double> %Y1.v.i2.2)
     54 ; CHECK: %Z1 = fadd <2 x double> %Y1, %X1.v.i1.2
     55 ; CHECK: %Z1.v.r1 = extractelement <2 x double> %Z1, i32 0
     56 ; CHECK: %Z1.v.r2 = extractelement <2 x double> %Z1, i32 1
     57 ; CHECK: %R = fmul double %Z1.v.r1, %Z1.v.r2
     58 ; CHECK: ret double %R
     59 }
     60 
     61 ; Basic depth-3 chain with cos
     62 define double @test2(double %A1, double %A2, double %B1, double %B2) {
     63 	%X1 = fsub double %A1, %B1
     64 	%X2 = fsub double %A2, %B2
     65 	%Y1 = call double @llvm.cos.f64(double %X1)
     66 	%Y2 = call double @llvm.cos.f64(double %X2)
     67 	%Z1 = fadd double %Y1, %B1
     68 	%Z2 = fadd double %Y2, %B2
     69 	%R  = fmul double %Z1, %Z2
     70 	ret double %R
     71 ; CHECK: @test2
     72 ; CHECK: %X1.v.i1.1 = insertelement <2 x double> undef, double %B1, i32 0
     73 ; CHECK: %X1.v.i1.2 = insertelement <2 x double> %X1.v.i1.1, double %B2, i32 1
     74 ; CHECK: %X1.v.i0.1 = insertelement <2 x double> undef, double %A1, i32 0
     75 ; CHECK: %X1.v.i0.2 = insertelement <2 x double> %X1.v.i0.1, double %A2, i32 1
     76 ; CHECK: %X1 = fsub <2 x double> %X1.v.i0.2, %X1.v.i1.2
     77 ; CHECK: %Y1 = call <2 x double> @llvm.cos.v2f64(<2 x double> %X1)
     78 ; CHECK: %Z1 = fadd <2 x double> %Y1, %X1.v.i1.2
     79 ; CHECK: %Z1.v.r1 = extractelement <2 x double> %Z1, i32 0
     80 ; CHECK: %Z1.v.r2 = extractelement <2 x double> %Z1, i32 1
     81 ; CHECK: %R = fmul double %Z1.v.r1, %Z1.v.r2
     82 ; CHECK: ret double %R
     83 }
     84 
     85 ; Basic depth-3 chain with powi
     86 define double @test3(double %A1, double %A2, double %B1, double %B2, i32 %P) {
     87 
     88 	%X1 = fsub double %A1, %B1
     89 	%X2 = fsub double %A2, %B2
     90 	%Y1 = call double @llvm.powi.f64(double %X1, i32 %P)
     91 	%Y2 = call double @llvm.powi.f64(double %X2, i32 %P)
     92 	%Z1 = fadd double %Y1, %B1
     93 	%Z2 = fadd double %Y2, %B2
     94 	%R  = fmul double %Z1, %Z2
     95 	ret double %R
     96 ; CHECK: @test3
     97 ; CHECK: %X1.v.i1.1 = insertelement <2 x double> undef, double %B1, i32 0
     98 ; CHECK: %X1.v.i1.2 = insertelement <2 x double> %X1.v.i1.1, double %B2, i32 1
     99 ; CHECK: %X1.v.i0.1 = insertelement <2 x double> undef, double %A1, i32 0
    100 ; CHECK: %X1.v.i0.2 = insertelement <2 x double> %X1.v.i0.1, double %A2, i32 1
    101 ; CHECK: %X1 = fsub <2 x double> %X1.v.i0.2, %X1.v.i1.2
    102 ; CHECK: %Y1 = call <2 x double> @llvm.powi.v2f64(<2 x double> %X1, i32 %P)
    103 ; CHECK: %Z1 = fadd <2 x double> %Y1, %X1.v.i1.2
    104 ; CHECK: %Z1.v.r1 = extractelement <2 x double> %Z1, i32 0
    105 ; CHECK: %Z1.v.r2 = extractelement <2 x double> %Z1, i32 1
    106 ; CHECK: %R = fmul double %Z1.v.r1, %Z1.v.r2
    107 ; CHECK: ret double %R
    108 }
    109 
    110 ; Basic depth-3 chain with powi (different powers: should not vectorize)
    111 define double @test4(double %A1, double %A2, double %B1, double %B2, i32 %P) {
    112 
    113 	%X1 = fsub double %A1, %B1
    114 	%X2 = fsub double %A2, %B2
    115         %P2 = add i32 %P, 1
    116 	%Y1 = call double @llvm.powi.f64(double %X1, i32 %P)
    117 	%Y2 = call double @llvm.powi.f64(double %X2, i32 %P2)
    118 	%Z1 = fadd double %Y1, %B1
    119 	%Z2 = fadd double %Y2, %B2
    120 	%R  = fmul double %Z1, %Z2
    121 	ret double %R
    122 ; CHECK: @test4
    123 ; CHECK-NOT: <2 x double>
    124 ; CHECK: ret double %R
    125 }
    126 
    127 ; CHECK: declare <2 x double> @llvm.fma.v2f64(<2 x double>, <2 x double>, <2 x double>) #0
    128 ; CHECK: declare <2 x double> @llvm.fmuladd.v2f64(<2 x double>, <2 x double>, <2 x double>) #0
    129 ; CHECK: declare <2 x double> @llvm.cos.v2f64(<2 x double>) #1
    130 ; CHECK: declare <2 x double> @llvm.powi.v2f64(<2 x double>, i32) #1
    131 
    132 ; CHECK: attributes #0 = { nounwind readnone }
    133 ; CHECK: attributes #1 = { nounwind readonly }
    134