1
Fork 0

Fix float add/mul reduction codegen

The accumulator is now respected for unordered reductions.
This commit is contained in:
Nikita Popov 2019-07-07 19:08:40 +02:00
parent 8789c9e595
commit 5c95f5fa6b
4 changed files with 9 additions and 2 deletions

View file

@ -249,6 +249,10 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
self.const_uint(self.type_i8(), i as u64) self.const_uint(self.type_i8(), i as u64)
} }
fn const_real(&self, t: &'ll Type, val: f64) -> &'ll Value {
unsafe { llvm::LLVMConstReal(t, val) }
}
fn const_struct( fn const_struct(
&self, &self,
elts: &[&'ll Value], elts: &[&'ll Value],

View file

@ -1663,9 +1663,10 @@ fn generic_simd_intrinsic(
acc acc
} else { } else {
// unordered arithmetic reductions do not: // unordered arithmetic reductions do not:
let identity_acc = if $name.contains("mul") { 1.0 } else { 0.0 };
match f.bit_width() { match f.bit_width() {
32 => bx.const_undef(bx.type_f32()), 32 => bx.const_real(bx.type_f32(), identity_acc),
64 => bx.const_undef(bx.type_f64()), 64 => bx.const_real(bx.type_f64(), identity_acc),
v => { v => {
return_error!(r#" return_error!(r#"
unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#, unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,

View file

@ -715,6 +715,7 @@ extern "C" {
// Operations on scalar constants // Operations on scalar constants
pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value; pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value;
pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value; pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value;
pub fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value;
pub fn LLVMConstIntGetZExtValue(ConstantVal: &Value) -> c_ulonglong; pub fn LLVMConstIntGetZExtValue(ConstantVal: &Value) -> c_ulonglong;
pub fn LLVMRustConstInt128Get(ConstantVal: &Value, SExt: bool, pub fn LLVMRustConstInt128Get(ConstantVal: &Value, SExt: bool,
high: &mut u64, low: &mut u64) -> bool; high: &mut u64, low: &mut u64) -> bool;

View file

@ -17,6 +17,7 @@ pub trait ConstMethods<'tcx>: BackendTypes {
fn const_u64(&self, i: u64) -> Self::Value; fn const_u64(&self, i: u64) -> Self::Value;
fn const_usize(&self, i: u64) -> Self::Value; fn const_usize(&self, i: u64) -> Self::Value;
fn const_u8(&self, i: u8) -> Self::Value; fn const_u8(&self, i: u8) -> Self::Value;
fn const_real(&self, t: Self::Type, val: f64) -> Self::Value;
fn const_struct(&self, elts: &[Self::Value], packed: bool) -> Self::Value; fn const_struct(&self, elts: &[Self::Value], packed: bool) -> Self::Value;