Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -2944,7 +2944,7 @@ Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align); Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant); Opts.FastRelaxedMath = Args.hasArg(OPT_cl_fast_relaxed_math); - if (Opts.FastRelaxedMath) + if (Opts.FastRelaxedMath || Args.hasArg(OPT_cl_mad_enable)) Opts.setDefaultFPContractMode(LangOptions::FPM_Fast); Opts.HexagonQdsp6Compat = Args.hasArg(OPT_mqdsp6_compat); Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map); Index: clang/test/CodeGenOpenCL/relaxed-fpmath.cl =================================================================== --- clang/test/CodeGenOpenCL/relaxed-fpmath.cl +++ clang/test/CodeGenOpenCL/relaxed-fpmath.cl @@ -12,10 +12,32 @@ // FAST: fdiv fast float // FINITE: fdiv nnan ninf float // UNSAFE: fdiv nnan nsz float - // MAD: fdiv float + // MAD: fdiv contract float // NOSIGNED: fdiv nsz float return a / b; } + +float fused_mad(float a, float b, float c) { + // NORMAL: @llvm.fmuladd.f32 + // FAST: fmul fast float + // FAST: fadd fast float + // MAD: fmul contract float + // MAD: fadd contract float + return a*b+c; +} + +float fused_mad_accross_stmts(float a, float b, float c) { + // NORMAL: fmul float + // NORMAL: fadd float + // FAST: fmul fast float + // FAST: fadd fast float + // MAD: fmul contract float + // MAD: fadd contract float + float t = a*b; + return t+c; +} + + // CHECK: attributes // NORMAL: "less-precise-fpmad"="false"