1; Test that the pow library call simplifier works correctly. 2 3; RUN: opt -instcombine -S < %s | FileCheck %s 4 5; Function Attrs: nounwind readnone 6declare double @llvm.pow.f64(double, double) 7declare float @llvm.pow.f32(float, float) 8 9; pow(x, 4.0f) 10define float @test_simplify_4f(float %x) { 11; CHECK-LABEL: @test_simplify_4f( 12; CHECK-NOT: pow 13; CHECK-NEXT: %1 = fmul float %x, %x 14; CHECK-NEXT: %2 = fmul float %1, %1 15; CHECK-NEXT: ret float %2 16 %1 = call fast float @llvm.pow.f32(float %x, float 4.000000e+00) 17 ret float %1 18} 19 20; pow(x, 3.0) 21define double @test_simplify_3(double %x) { 22; CHECK-LABEL: @test_simplify_3( 23; CHECK-NOT: pow 24; CHECK-NEXT: %1 = fmul double %x, %x 25; CHECK-NEXT: %2 = fmul double %1, %x 26; CHECK-NEXT: ret double %2 27 %1 = call fast double @llvm.pow.f64(double %x, double 3.000000e+00) 28 ret double %1 29} 30 31; pow(x, 4.0) 32define double @test_simplify_4(double %x) { 33; CHECK-LABEL: @test_simplify_4( 34; CHECK-NOT: pow 35; CHECK-NEXT: %1 = fmul double %x, %x 36; CHECK-NEXT: %2 = fmul double %1, %1 37; CHECK-NEXT: ret double %2 38 %1 = call fast double @llvm.pow.f64(double %x, double 4.000000e+00) 39 ret double %1 40} 41 42; pow(x, 15.0) 43define double @test_simplify_15(double %x) { 44; CHECK-LABEL: @test_simplify_15( 45; CHECK-NOT: pow 46; CHECK-NEXT: %1 = fmul double %x, %x 47; CHECK-NEXT: %2 = fmul double %1, %x 48; CHECK-NEXT: %3 = fmul double %2, %2 49; CHECK-NEXT: %4 = fmul double %3, %3 50; CHECK-NEXT: %5 = fmul double %2, %4 51; CHECK-NEXT: ret double %5 52 %1 = call fast double @llvm.pow.f64(double %x, double 1.500000e+01) 53 ret double %1 54} 55 56; pow(x, -7.0) 57define double @test_simplify_neg_7(double %x) { 58; CHECK-LABEL: @test_simplify_neg_7( 59; CHECK-NOT: pow 60; CHECK-NEXT: %1 = fmul double %x, %x 61; CHECK-NEXT: %2 = fmul double %1, %x 62; CHECK-NEXT: %3 = fmul double %1, %2 63; CHECK-NEXT: %4 = fmul double %1, %3 64; CHECK-NEXT: %5 = fdiv double 1.000000e+00, %4 65; CHECK-NEXT: ret double %5 66 %1 = call fast double @llvm.pow.f64(double %x, double -7.000000e+00) 67 ret double %1 68} 69 70; pow(x, -19.0) 71define double @test_simplify_neg_19(double %x) { 72; CHECK-LABEL: @test_simplify_neg_19( 73; CHECK-NOT: pow 74; CHECK-NEXT: %1 = fmul double %x, %x 75; CHECK-NEXT: %2 = fmul double %1, %1 76; CHECK-NEXT: %3 = fmul double %2, %2 77; CHECK-NEXT: %4 = fmul double %3, %3 78; CHECK-NEXT: %5 = fmul double %1, %4 79; CHECK-NEXT: %6 = fmul double %5, %x 80; CHECK-NEXT: %7 = fdiv double 1.000000e+00, %6 81; CHECK-NEXT: ret double %7 82 %1 = call fast double @llvm.pow.f64(double %x, double -1.900000e+01) 83 ret double %1 84} 85 86; pow(x, 11.23) 87define double @test_simplify_11_23(double %x) { 88; CHECK-LABEL: @test_simplify_11_23( 89; CHECK-NOT: fmul 90; CHECK-NEXT: %1 = call fast double @llvm.pow.f64(double %x, double 1.123000e+01) 91; CHECK-NEXT: ret double %1 92 %1 = call fast double @llvm.pow.f64(double %x, double 1.123000e+01) 93 ret double %1 94} 95 96; pow(x, 32.0) 97define double @test_simplify_32(double %x) { 98; CHECK-LABEL: @test_simplify_32( 99; CHECK-NOT: pow 100; CHECK-NEXT: %1 = fmul double %x, %x 101; CHECK-NEXT: %2 = fmul double %1, %1 102; CHECK-NEXT: %3 = fmul double %2, %2 103; CHECK-NEXT: %4 = fmul double %3, %3 104; CHECK-NEXT: %5 = fmul double %4, %4 105; CHECK-NEXT: ret double %5 106 %1 = call fast double @llvm.pow.f64(double %x, double 3.200000e+01) 107 ret double %1 108} 109 110; pow(x, 33.0) 111define double @test_simplify_33(double %x) { 112; CHECK-LABEL: @test_simplify_33( 113; CHECK-NOT: fmul 114; CHECK-NEXT: %1 = call fast double @llvm.pow.f64(double %x, double 3.300000e+01) 115; CHECK-NEXT: ret double %1 116 %1 = call fast double @llvm.pow.f64(double %x, double 3.300000e+01) 117 ret double %1 118} 119 120