Home | History | Annotate | Download | only in CodeGen
      1 // RUN: %clang_cc1 -fmath-errno -emit-llvm -o - %s -triple i386-unknown-unknown | FileCheck -check-prefix CHECK-YES %s
      2 // RUN: %clang_cc1 -emit-llvm -o - %s -triple i386-unknown-unknown | FileCheck -check-prefix CHECK-NO %s
      3 // RUN: %clang_cc1 -menable-unsafe-fp-math -emit-llvm -o - %s -triple i386-unknown-unknown | FileCheck -check-prefix CHECK-FAST %s
      4 
      5 // CHECK-YES-LABEL: define void @test_sqrt
      6 // CHECK-NO-LABEL: define void @test_sqrt
      7 // CHECK-FAST-LABEL: define void @test_sqrt
      8 void test_sqrt(float a0, double a1, long double a2) {
      9   // Following llvm-gcc's lead, we never emit these as intrinsics;
     10   // no-math-errno isn't good enough.  We could probably use intrinsics
     11   // with appropriate guards if it proves worthwhile.
     12 
     13   // CHECK-YES: call float @sqrtf
     14   // CHECK-NO: call float @sqrtf
     15   float l0 = sqrtf(a0);
     16 
     17   // CHECK-YES: call double @sqrt
     18   // CHECK-NO: call double @sqrt
     19   double l1 = sqrt(a1);
     20 
     21   // CHECK-YES: call x86_fp80 @sqrtl
     22   // CHECK-NO: call x86_fp80 @sqrtl
     23   long double l2 = sqrtl(a2);
     24 }
     25 
     26 // CHECK-YES: declare float @sqrtf(float)
     27 // CHECK-YES: declare double @sqrt(double)
     28 // CHECK-YES: declare x86_fp80 @sqrtl(x86_fp80)
     29 // CHECK-NO: declare float @sqrtf(float) [[NUW_RN:#[0-9]+]]
     30 // CHECK-NO: declare double @sqrt(double) [[NUW_RN]]
     31 // CHECK-NO: declare x86_fp80 @sqrtl(x86_fp80) [[NUW_RN]]
     32 // CHECK-FAST: declare float @llvm.sqrt.f32(float)
     33 // CHECK-FAST: declare double @llvm.sqrt.f64(double)
     34 // CHECK-FAST: declare x86_fp80 @llvm.sqrt.f80(x86_fp80)
     35 
     36 // CHECK-YES-LABEL: define void @test_pow
     37 // CHECK-NO-LABEL: define void @test_pow
     38 void test_pow(float a0, double a1, long double a2) {
     39   // CHECK-YES: call float @powf
     40   // CHECK-NO: call float @llvm.pow.f32
     41   float l0 = powf(a0, a0);
     42 
     43   // CHECK-YES: call double @pow
     44   // CHECK-NO: call double @llvm.pow.f64
     45   double l1 = pow(a1, a1);
     46 
     47   // CHECK-YES: call x86_fp80 @powl
     48   // CHECK-NO: call x86_fp80 @llvm.pow.f80
     49   long double l2 = powl(a2, a2);
     50 }
     51 
     52 // CHECK-YES: declare float @powf(float, float)
     53 // CHECK-YES: declare double @pow(double, double)
     54 // CHECK-YES: declare x86_fp80 @powl(x86_fp80, x86_fp80)
     55 // CHECK-NO: declare float @llvm.pow.f32(float, float) [[NUW_RNI:#[0-9]+]]
     56 // CHECK-NO: declare double @llvm.pow.f64(double, double) [[NUW_RNI]]
     57 // CHECK-NO: declare x86_fp80 @llvm.pow.f80(x86_fp80, x86_fp80) [[NUW_RNI]]
     58 
     59 // CHECK-YES-LABEL: define void @test_fma
     60 // CHECK-NO-LABEL: define void @test_fma
     61 void test_fma(float a0, double a1, long double a2) {
     62     // CHECK-YES: call float @llvm.fma.f32
     63     // CHECK-NO: call float @llvm.fma.f32
     64     float l0 = fmaf(a0, a0, a0);
     65 
     66     // CHECK-YES: call double @llvm.fma.f64
     67     // CHECK-NO: call double @llvm.fma.f64
     68     double l1 = fma(a1, a1, a1);
     69 
     70     // CHECK-YES: call x86_fp80 @llvm.fma.f80
     71     // CHECK-NO: call x86_fp80 @llvm.fma.f80
     72     long double l2 = fmal(a2, a2, a2);
     73 }
     74 
     75 // CHECK-YES: declare float @llvm.fma.f32(float, float, float) [[NUW_RN:#[0-9]+]]
     76 // CHECK-YES: declare double @llvm.fma.f64(double, double, double) [[NUW_RN]]
     77 // CHECK-YES: declare x86_fp80 @llvm.fma.f80(x86_fp80, x86_fp80, x86_fp80) [[NUW_RN]]
     78 // CHECK-NO: declare float @llvm.fma.f32(float, float, float) [[NUW_RN2:#[0-9]+]]
     79 // CHECK-NO: declare double @llvm.fma.f64(double, double, double) [[NUW_RN2]]
     80 // CHECK-NO: declare x86_fp80 @llvm.fma.f80(x86_fp80, x86_fp80, x86_fp80) [[NUW_RN2]]
     81 
     82 // Just checking to make sure these library functions are marked readnone
     83 void test_builtins(double d, float f, long double ld) {
     84 // CHECK-NO: @test_builtins
     85 // CHECK-YES: @test_builtins
     86   double atan_ = atan(d);
     87   long double atanl_ = atanl(ld);
     88   float atanf_ = atanf(f);
     89 // CHECK-NO: declare double @atan(double) [[NUW_RN]]
     90 // CHECK-NO: declare x86_fp80 @atanl(x86_fp80) [[NUW_RN]]
     91 // CHECK-NO: declare float @atanf(float) [[NUW_RN]]
     92 // CHECK-YES-NOT: declare double @atan(double) [[NUW_RN]]
     93 // CHECK-YES-NOT: declare x86_fp80 @atanl(x86_fp80) [[NUW_RN]]
     94 // CHECK-YES-NOT: declare float @atanf(float) [[NUW_RN]]
     95 
     96   double atan2_ = atan2(d, 2);
     97   long double atan2l_ = atan2l(ld, ld);
     98   float atan2f_ = atan2f(f, f);
     99 // CHECK-NO: declare double @atan2(double, double) [[NUW_RN]]
    100 // CHECK-NO: declare x86_fp80 @atan2l(x86_fp80, x86_fp80) [[NUW_RN]]
    101 // CHECK-NO: declare float @atan2f(float, float) [[NUW_RN]]
    102 // CHECK-YES-NOT: declare double @atan2(double, double) [[NUW_RN]]
    103 // CHECK-YES-NOT: declare x86_fp80 @atan2l(x86_fp80, x86_fp80) [[NUW_RN]]
    104 // CHECK-YES-NOT: declare float @atan2f(float, float) [[NUW_RN]]
    105 
    106   double exp_ = exp(d);
    107   long double expl_ = expl(ld);
    108   float expf_ = expf(f);
    109 // CHECK-NO: declare double @exp(double) [[NUW_RN]]
    110 // CHECK-NO: declare x86_fp80 @expl(x86_fp80) [[NUW_RN]]
    111 // CHECK-NO: declare float @expf(float) [[NUW_RN]]
    112 // CHECK-YES-NOT: declare double @exp(double) [[NUW_RN]]
    113 // CHECK-YES-NOT: declare x86_fp80 @expl(x86_fp80) [[NUW_RN]]
    114 // CHECK-YES-NOT: declare float @expf(float) [[NUW_RN]]
    115 
    116   double log_ = log(d);
    117   long double logl_ = logl(ld);
    118   float logf_ = logf(f);
    119 // CHECK-NO: declare double @log(double) [[NUW_RN]]
    120 // CHECK-NO: declare x86_fp80 @logl(x86_fp80) [[NUW_RN]]
    121 // CHECK-NO: declare float @logf(float) [[NUW_RN]]
    122 // CHECK-YES-NOT: declare double @log(double) [[NUW_RN]]
    123 // CHECK-YES-NOT: declare x86_fp80 @logl(x86_fp80) [[NUW_RN]]
    124 // CHECK-YES-NOT: declare float @logf(float) [[NUW_RN]]
    125 }
    126 
    127 // CHECK-YES: attributes [[NUW_RN]] = { nounwind readnone }
    128 
    129 // CHECK-NO: attributes [[NUW_RN]] = { nounwind readnone{{.*}} }
    130 // CHECK-NO: attributes [[NUW_RNI]] = { nounwind readnone }
    131