brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.2 KiB · 237c9d4 Raw
290 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffp-contract=on -DDEFAULT=1 -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-DDEFAULT %s2// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffp-contract=on -DEBSTRICT=1 -ffp-exception-behavior=strict -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-DEBSTRICT %s3// RUN: %clang_cc1 -triple x86_64-linux-gnu -DFAST=1 -ffast-math -ffp-contract=fast -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-FAST %s4// RUN: %clang_cc1 -triple x86_64-linux-gnu -ffp-contract=on -DNOHONOR=1 -ffinite-math-only -menable-no-infs -menable-no-nans -emit-llvm -o - %s | FileCheck --check-prefix=CHECK-NOHONOR %s5 6#define FUN(n) \7  (float z) { return n * z + n; }8 9// CHECK-DDEFAULT: Function Attrs: mustprogress noinline nounwind optnone{{$$}}10// CHECK-DEBSTRICT: Function Attrs: mustprogress noinline nounwind optnone strictfp{{$$}}11// CHECK-FAST: Function Attrs: mustprogress noinline nounwind optnone{{$$}}12// CHECK-NOHONOR: Function Attrs: mustprogress noinline nounwind optnone{{$$}}13float fun_default FUN(1)14//CHECK-LABEL: define {{.*}} @_Z11fun_defaultf{{.*}}15#if DEFAULT16//CHECK-DDEFAULT: call float @llvm.fmuladd{{.*}}17#endif18#if EBSTRICT19// Note that backend wants constrained intrinsics used20// throughout the function if they are needed anywhere in the function.21// In that case, operations are built with constrained intrinsics operator22// but using default settings for exception behavior and rounding mode.23//CHECK-DEBSTRICT: llvm.experimental.constrained.fmul{{.*}}tonearest{{.*}}strict24#endif25#if FAST26//CHECK-FAST: fmul fast float27//CHECK-FAST: fadd fast float28#endif29 30#pragma float_control(push)31#ifndef FAST32// Rule: precise must be enabled33#pragma float_control(except, on)34#endif35    // CHECK-FAST: Function Attrs: mustprogress noinline nounwind optnone{{$$}}36    // CHECK-DDEFAULT: Function Attrs: mustprogress noinline nounwind optnone strictfp{{$$}}37    // CHECK-DEBSTRICT: Function Attrs: mustprogress noinline nounwind optnone strictfp{{$$}}38    // CHECK-NOHONOR: Function Attrs: mustprogress noinline nounwind optnone strictfp{{$$}}39    float exc_on FUN(2)40//CHECK-LABEL: define {{.*}} @_Z6exc_onf{{.*}}41#if DEFAULT42//CHECK-DDEFAULT: llvm.experimental.constrained.fmul{{.*}}43#endif44#if EBSTRICT45//CHECK-DEBSTRICT: llvm.experimental.constrained.fmuladd{{.*}}tonearest{{.*}}strict46#endif47#if NOHONOR48//CHECK-NOHONOR: nnan ninf float {{.*}}llvm.experimental.constrained.fmuladd{{.*}}tonearest{{.*}}strict49#endif50#if FAST51//Not possible to enable float_control(except) in FAST mode.52//CHECK-FAST: fmul fast float53//CHECK-FAST: fadd fast float54#endif55 56#pragma float_control(pop)57    // CHECK-DDEFAULT: Function Attrs: mustprogress noinline nounwind optnone{{$$}}58    // CHECK-DEBSTRICT: Function Attrs: mustprogress noinline nounwind optnone strictfp{{$$}}59    // CHECK-FAST: Function Attrs: mustprogress noinline nounwind optnone{{$$}}60    // CHECK-NOHONOR: Function Attrs: mustprogress noinline nounwind optnone{{$$}}61    float exc_pop FUN(5)62//CHECK-LABEL: define {{.*}} @_Z7exc_popf{{.*}}63#if DEFAULT64//CHECK-DDEFAULT: call float @llvm.fmuladd{{.*}}65#endif66#if EBSTRICT67//CHECK-DEBSTRICT: llvm.experimental.constrained.fmuladd{{.*}}tonearest{{.*}}strict68#endif69#if NOHONOR70//CHECK-NOHONOR: call nnan ninf float @llvm.fmuladd{{.*}}71#endif72#if FAST73//CHECK-FAST: fmul fast float74//CHECK-FAST: fadd fast float75#endif76 77#pragma float_control(except, off)78        float exc_off FUN(5)79//CHECK-LABEL: define {{.*}} @_Z7exc_offf{{.*}}80#if DEFAULT81//CHECK-DDEFAULT: call float @llvm.fmuladd{{.*}}82#endif83#if EBSTRICT84//CHECK-DEBSTRICT: call float @llvm.fmuladd{{.*}}85#endif86#if NOHONOR87//CHECK-NOHONOR: call nnan ninf float @llvm.fmuladd{{.*}}88#endif89#if FAST90//CHECK-FAST: fmul fast float91//CHECK-FAST: fadd fast float92#endif93 94#pragma float_control(precise, on, push)95            float precise_on FUN(3)96//CHECK-LABEL: define {{.*}} @_Z10precise_onf{{.*}}97#if DEFAULT98//CHECK-DDEFAULT: float {{.*}}llvm.fmuladd{{.*}}99#endif100#if EBSTRICT101//CHECK-DEBSTRICT: float {{.*}}llvm.fmuladd{{.*}}102#endif103#if NOHONOR104// If precise is pushed then all fast-math should be off!105//CHECK-NOHONOR: call float {{.*}}llvm.fmuladd{{.*}}106#endif107#if FAST108//CHECK-FAST: float {{.*}}llvm.fmuladd{{.*}}109#endif110 111#pragma float_control(pop)112                float precise_pop FUN(3)113//CHECK-LABEL: define {{.*}} @_Z11precise_popf{{.*}}114#if DEFAULT115//CHECK-DDEFAULT: float {{.*}}llvm.fmuladd{{.*}}116#endif117#if EBSTRICT118//CHECK-DEBSTRICT: float {{.*}}llvm.fmuladd{{.*}}119#endif120#if NOHONOR121//CHECK-NOHONOR: call nnan ninf float @llvm.fmuladd{{.*}}122#endif123#if FAST124//CHECK-FAST: fmul fast float125//CHECK-FAST: fadd fast float126#endif127#pragma float_control(precise, off)128                    float precise_off FUN(4)129//CHECK-LABEL: define {{.*}} @_Z11precise_offf{{.*}}130#if DEFAULT131// Note: precise_off enables fp_contract=fast and the instructions132// generated do not include the contract flag, although it was enabled133// in IRBuilder.134//CHECK-DDEFAULT: fmul fast float135//CHECK-DDEFAULT: fadd fast float136#endif137#if EBSTRICT138//CHECK-DEBSTRICT: fmul fast float139//CHECK-DEBSTRICT: fadd fast float140#endif141#if NOHONOR142// fast math should be enabled, and contract should be fast143//CHECK-NOHONOR: fmul fast float144//CHECK-NOHONOR: fadd fast float145#endif146#if FAST147//CHECK-FAST: fmul fast float148//CHECK-FAST: fadd fast float149#endif150 151#pragma float_control(precise, on)152                        float precise_on2 FUN(3)153//CHECK-LABEL: define {{.*}} @_Z11precise_on2f{{.*}}154#if DEFAULT155//CHECK-DDEFAULT: llvm.fmuladd{{.*}}156#endif157#if EBSTRICT158//CHECK-DEBSTRICT: float {{.*}}llvm.fmuladd{{.*}}159#endif160#if NOHONOR161// fast math should be off, and contract should be on162//CHECK-NOHONOR: float {{.*}}llvm.fmuladd{{.*}}163#endif164#if FAST165//CHECK-FAST: float {{.*}}llvm.fmuladd{{.*}}166#endif167 168#pragma float_control(push)169                            float precise_push FUN(3)170//CHECK-LABEL: define {{.*}} @_Z12precise_pushf{{.*}}171#if DEFAULT172//CHECK-DDEFAULT: llvm.fmuladd{{.*}}173#endif174#if EBSTRICT175//CHECK-DEBSTRICT: float {{.*}}llvm.fmuladd{{.*}}176#endif177#if NOHONOR178//CHECK-NOHONOR: float {{.*}}llvm.fmuladd{{.*}}179#endif180#if FAST181//CHECK-FAST: float {{.*}}llvm.fmuladd{{.*}}182#endif183 184#pragma float_control(precise, off)185                                float precise_off2 FUN(4)186//CHECK-LABEL: define {{.*}} @_Z12precise_off2f{{.*}}187#if DEFAULT188//CHECK-DDEFAULT: fmul fast float189//CHECK-DDEFAULT: fadd fast float190#endif191#if EBSTRICT192//CHECK-DEBSTRICT: fmul fast float193//CHECK-DEBSTRICT: fadd fast float194#endif195#if NOHONOR196// fast math settings since precise is off197//CHECK-NOHONOR: fmul fast float198//CHECK-NOHONOR: fadd fast float199#endif200#if FAST201//CHECK-FAST: fmul fast float202//CHECK-FAST: fadd fast float203#endif204 205#pragma float_control(pop)206                                    float precise_pop2 FUN(3)207//CHECK-LABEL: define {{.*}} @_Z12precise_pop2f{{.*}}208#if DEFAULT209//CHECK-DDEFAULT: llvm.fmuladd{{.*}}210#endif211#if EBSTRICT212//CHECK-DEBSTRICT: float {{.*}}llvm.fmuladd{{.*}}213#endif214#if NOHONOR215//CHECK-NOHONOR: float {{.*}}llvm.fmuladd{{.*}}216#endif217#if FAST218//CHECK-FAST: float {{.*}}llvm.fmuladd{{.*}}219#endif220 221#ifndef FAST222// Rule: precise must be enabled223#pragma float_control(except, on)224#endif225                                        float y();226// CHECK-DDEFAULT: Function Attrs: mustprogress noinline nounwind optnone{{$$}}227// CHECK-DEBSTRICT: Function Attrs: mustprogress noinline nounwind optnone strictfp{{$$}}228// CHECK-FAST: Function Attrs: mustprogress noinline nounwind optnone{{$$}}229// CHECK-NOHONOR: Function Attrs: mustprogress noinline nounwind optnone{{$$}}230class ON {231  // Settings for top level class initializer use program source setting.232  float z = 2 + y() * 7;233//CHECK-LABEL: define {{.*}} void @_ZN2ONC2Ev{{.*}}234#if DEFAULT235// CHECK-DDEFAULT: llvm.experimental.constrained.fmul{{.*}}tonearest{{.*}}strict236#endif237#if EBSTRICT238// CHECK-DEBSTRICT: llvm.experimental.constrained.fmul{{.*}}tonearest{{.*}}strict239#endif240#if NOHONOR241// CHECK-NOHONOR: llvm.experimental.constrained.fmul{{.*}}tonearest{{.*}}strict242#endif243#if FAST244// CHECK-FAST: float {{.*}}llvm.fmuladd{{.*}}245#endif246};247ON on;248#pragma float_control(except, off)249// CHECK-DDEFAULT: Function Attrs: mustprogress noinline nounwind optnone{{$$}}250// CHECK-DEBSTRICT: Function Attrs: mustprogress noinline nounwind optnone{{$$}}251// CHECK-FAST: Function Attrs: mustprogress noinline nounwind optnone{{$$}}252// CHECK-NOHONOR: Function Attrs: mustprogress noinline nounwind optnone{{$$}}253class OFF {254  float w = 2 + y() * 7;255// CHECK-LABEL: define {{.*}} void @_ZN3OFFC2Ev{{.*}}256// CHECK: call float {{.*}}llvm.fmuladd257};258OFF off;259 260#pragma clang fp reassociate(on)261struct MyComplex {262  float xx;263  float yy;264  MyComplex(float x, float y) {265    xx = x;266    yy = y;267  }268  MyComplex() {}269  const MyComplex operator+(const MyComplex other) const {270// CHECK-LABEL: define {{.*}} @_ZNK9MyComplexplES_271// CHECK: fadd reassoc float272// CHECK: fadd reassoc float273    return MyComplex(xx + other.xx, yy + other.yy);274  }275};276MyComplex useAdd() {277  MyComplex a (1, 3);278  MyComplex b (2, 4);279   return a + b;280}281 282// CHECK-DDEFAULT: Function Attrs: noinline nounwind{{$$}}283// CHECK-DEBSTRICT: Function Attrs: noinline nounwind strictfp{{$$}}284// CHECK-FAST: Function Attrs: noinline nounwind{{$$}}285// CHECK-NOHONOR: Function Attrs: noinline nounwind{{$$}}286// CHECK-LABEL: define{{.*}} @_GLOBAL__sub_I_fp_floatcontrol_stack287 288// CHECK-DEBSTRICT: {{[ ]}}strictfp{{[ ]}}289// CHECK-DEBSTRICT-NOT: "strictfp"290