unsigned SpellChecking : 1; // Whether to perform spell-checking for error
// recovery.
+ unsigned SinglePrecisionConstants : 1; // Whether to treat double-precision
+ // floating point constants as
+ // single precision constants.
// FIXME: This is just a temporary option, for testing purposes.
unsigned NoBitFieldTypeAlign : 1;
DumpRecordLayouts = 0;
DumpVTableLayouts = 0;
SpellChecking = 1;
+ SinglePrecisionConstants = 0;
NoBitFieldTypeAlign = 0;
}
def cl_opt_disable : Flag<"-cl-opt-disable">,
HelpText<"OpenCL only. This option disables all optimizations. The default is optimizations are enabled.">;
+def cl_single_precision_constant : Flag<"-cl-single-precision-constant">,
+ HelpText<"OpenCL only. Treat double precision floating-point constant as single precision constant.">;
Opts.DumpVTableLayouts = Args.hasArg(OPT_fdump_vtable_layouts);
Opts.SpellChecking = !Args.hasArg(OPT_fno_spell_checking);
Opts.NoBitFieldTypeAlign = Args.hasArg(OPT_fno_bitfield_type_align);
+ Opts.SinglePrecisionConstants = Args.hasArg(OPT_cl_single_precision_constant);
Opts.OptimizeSize = 0;
// FIXME: Eliminate this dependency.
bool isExact = (result == APFloat::opOK);
Res = FloatingLiteral::Create(Context, Val, isExact, Ty, Tok.getLocation());
+ if (getLangOptions().SinglePrecisionConstants && Ty == Context.DoubleTy)
+ ImpCastExprToType(Res, Context.FloatTy, CK_FloatingCast);
+
} else if (!Literal.isIntegerLiteral()) {
return ExprError();
} else {
--- /dev/null
+// RUN: %clang_cc1 %s -x cl -cl-single-precision-constant -emit-llvm -o - | FileCheck %s
+
+float fn(float f) {
+ // CHECK: fmul float
+ // CHECK: fadd float
+ return f*2. + 1.;
+}