@@ -4274,12 +4274,37 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
4274
4274
*this, E, GetIntrinsicID(E->getArg(0)->getType()), "rdx.min"));
4275
4275
}
4276
4276
4277
- case Builtin::BI__builtin_reduce_add:
4277
+ case Builtin::BI__builtin_reduce_add: {
4278
+ // Note: vector_reduce_fadd takes two arguments a
4279
+ // scalar start value and a vector. That would mean to
4280
+ // correctly call it we would need emitBuiltinWithOneOverloadedType<2>
4281
+ // To keep the builtin sema behavior the same despite type we will
4282
+ // popululate vector_reduce_fadd scalar value with a 0.
4283
+ if (E->getArg(0)->getType()->hasFloatingRepresentation()) {
4284
+ Value *X = EmitScalarExpr(E->getArg(0));
4285
+ auto EltTy = X->getType()->getScalarType();
4286
+ Value *Seed = ConstantFP::get(EltTy, 0);
4287
+ return RValue::get(Builder.CreateIntrinsic(
4288
+ /*ReturnType=*/EltTy, llvm::Intrinsic::vector_reduce_fadd,
4289
+ ArrayRef<Value *>{Seed, X}, nullptr, "rdx.fadd"));
4290
+ }
4291
+ assert(E->getArg(0)->getType()->hasIntegerRepresentation());
4278
4292
return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4279
4293
*this, E, llvm::Intrinsic::vector_reduce_add, "rdx.add"));
4280
- case Builtin::BI__builtin_reduce_mul:
4294
+ }
4295
+ case Builtin::BI__builtin_reduce_mul: {
4296
+ if (E->getArg(0)->getType()->hasFloatingRepresentation()) {
4297
+ Value *X = EmitScalarExpr(E->getArg(0));
4298
+ auto EltTy = X->getType()->getScalarType();
4299
+ Value *Seed = ConstantFP::get(EltTy, 0);
4300
+ return RValue::get(Builder.CreateIntrinsic(
4301
+ /*ReturnType=*/EltTy, llvm::Intrinsic::vector_reduce_fmul,
4302
+ ArrayRef<Value *>{Seed, X}, nullptr, "rdx.fmul"));
4303
+ }
4304
+ assert(E->getArg(0)->getType()->hasIntegerRepresentation());
4281
4305
return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4282
4306
*this, E, llvm::Intrinsic::vector_reduce_mul, "rdx.mul"));
4307
+ }
4283
4308
case Builtin::BI__builtin_reduce_xor:
4284
4309
return RValue::get(emitBuiltinWithOneOverloadedType<1>(
4285
4310
*this, E, llvm::Intrinsic::vector_reduce_xor, "rdx.xor"));
0 commit comments