@@ -532,13 +532,13 @@ static Value *emitCallMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
532
532
533
533
// Emit a simple mangled intrinsic that has 1 argument and a return type
534
534
// matching the argument type.
535
- static Value *emitUnaryBuiltin(CodeGenFunction &CGF, const CallExpr *E,
536
- unsigned IntrinsicID ,
537
- llvm::StringRef Name = "" ) {
535
+ static Value *emitUnaryBuiltin(CodeGenFunction &CGF,
536
+ const CallExpr *E ,
537
+ unsigned IntrinsicID ) {
538
538
llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
539
539
540
540
Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
541
- return CGF.Builder.CreateCall(F, Src0, Name );
541
+ return CGF.Builder.CreateCall(F, Src0);
542
542
}
543
543
544
544
// Emit an intrinsic that has 2 operands of the same type as its result.
@@ -3122,24 +3122,23 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
3122
3122
}
3123
3123
3124
3124
case Builtin::BI__builtin_elementwise_abs: {
3125
+ Value *Op0 = EmitScalarExpr(E->getArg(0));
3125
3126
Value *Result;
3126
- QualType QT = E->getArg(0)->getType();
3127
-
3128
- if (auto *VecTy = QT->getAs<VectorType>())
3129
- QT = VecTy->getElementType();
3130
- if (QT->isIntegerType())
3127
+ if (Op0->getType()->isIntOrIntVectorTy())
3131
3128
Result = Builder.CreateBinaryIntrinsic(
3132
- llvm::Intrinsic::abs, EmitScalarExpr(E->getArg(0)),
3133
- Builder.getFalse(), nullptr, "elt.abs");
3129
+ llvm::Intrinsic::abs, Op0, Builder.getFalse(), nullptr, "elt.abs");
3134
3130
else
3135
- Result = emitUnaryBuiltin(*this, E, llvm::Intrinsic::fabs, "elt.abs");
3136
-
3131
+ Result = Builder.CreateUnaryIntrinsic( llvm::Intrinsic::fabs, Op0, nullptr,
3132
+ "elt.abs");
3137
3133
return RValue::get(Result);
3138
3134
}
3139
3135
3140
- case Builtin::BI__builtin_elementwise_ceil:
3141
- return RValue::get(
3142
- emitUnaryBuiltin(*this, E, llvm::Intrinsic::ceil, "elt.ceil"));
3136
+ case Builtin::BI__builtin_elementwise_ceil: {
3137
+ Value *Op0 = EmitScalarExpr(E->getArg(0));
3138
+ Value *Result = Builder.CreateUnaryIntrinsic(llvm::Intrinsic::ceil, Op0,
3139
+ nullptr, "elt.ceil");
3140
+ return RValue::get(Result);
3141
+ }
3143
3142
3144
3143
case Builtin::BI__builtin_elementwise_max: {
3145
3144
Value *Op0 = EmitScalarExpr(E->getArg(0));
@@ -3175,39 +3174,49 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
3175
3174
}
3176
3175
3177
3176
case Builtin::BI__builtin_reduce_max: {
3178
- auto GetIntrinsicID = [](QualType QT) {
3179
- if (auto *VecTy = QT->getAs<VectorType>())
3180
- QT = VecTy->getElementType();
3181
- if (QT->isSignedIntegerType())
3182
- return llvm::Intrinsic::vector_reduce_smax;
3183
- if (QT->isUnsignedIntegerType())
3184
- return llvm::Intrinsic::vector_reduce_umax;
3185
- assert(QT->isFloatingType() && "must have a float here");
3177
+ auto GetIntrinsicID = [](QualType QT, llvm::Type *IrTy) {
3178
+ if (IrTy->isIntOrIntVectorTy()) {
3179
+ if (auto *VecTy = QT->getAs<VectorType>())
3180
+ QT = VecTy->getElementType();
3181
+ if (QT->isSignedIntegerType())
3182
+ return llvm::Intrinsic::vector_reduce_smax;
3183
+ else
3184
+ return llvm::Intrinsic::vector_reduce_umax;
3185
+ }
3186
3186
return llvm::Intrinsic::vector_reduce_fmax;
3187
3187
};
3188
- return RValue::get(emitUnaryBuiltin(
3189
- *this, E, GetIntrinsicID(E->getArg(0)->getType()), "rdx.min"));
3188
+ Value *Op0 = EmitScalarExpr(E->getArg(0));
3189
+ Value *Result = Builder.CreateUnaryIntrinsic(
3190
+ GetIntrinsicID(E->getArg(0)->getType(), Op0->getType()), Op0, nullptr,
3191
+ "rdx.min");
3192
+ return RValue::get(Result);
3190
3193
}
3191
3194
3192
3195
case Builtin::BI__builtin_reduce_min: {
3193
- auto GetIntrinsicID = [](QualType QT) {
3194
- if (auto *VecTy = QT->getAs<VectorType>())
3195
- QT = VecTy->getElementType();
3196
- if (QT->isSignedIntegerType())
3197
- return llvm::Intrinsic::vector_reduce_smin;
3198
- if (QT->isUnsignedIntegerType())
3199
- return llvm::Intrinsic::vector_reduce_umin;
3200
- assert(QT->isFloatingType() && "must have a float here");
3196
+ auto GetIntrinsicID = [](QualType QT, llvm::Type *IrTy) {
3197
+ if (IrTy->isIntOrIntVectorTy()) {
3198
+ if (auto *VecTy = QT->getAs<VectorType>())
3199
+ QT = VecTy->getElementType();
3200
+ if (QT->isSignedIntegerType())
3201
+ return llvm::Intrinsic::vector_reduce_smin;
3202
+ else
3203
+ return llvm::Intrinsic::vector_reduce_umin;
3204
+ }
3201
3205
return llvm::Intrinsic::vector_reduce_fmin;
3202
3206
};
3203
-
3204
- return RValue::get(emitUnaryBuiltin(
3205
- *this, E, GetIntrinsicID(E->getArg(0)->getType()), "rdx.min"));
3207
+ Value *Op0 = EmitScalarExpr(E->getArg(0));
3208
+ Value *Result = Builder.CreateUnaryIntrinsic(
3209
+ GetIntrinsicID(E->getArg(0)->getType(), Op0->getType()), Op0, nullptr,
3210
+ "rdx.min");
3211
+ return RValue::get(Result);
3206
3212
}
3207
3213
3208
- case Builtin::BI__builtin_reduce_xor:
3209
- return RValue::get(emitUnaryBuiltin(
3210
- *this, E, llvm::Intrinsic::vector_reduce_xor, "rdx.xor"));
3214
+ case Builtin::BI__builtin_reduce_xor: {
3215
+ Value *Op0 = EmitScalarExpr(E->getArg(0));
3216
+ Value *Result = Builder.CreateUnaryIntrinsic(
3217
+ llvm::Intrinsic::vector_reduce_xor, Op0, nullptr, "rdx.xor");
3218
+ return RValue::get(Result);
3219
+ }
3211
3220
3212
3221
case Builtin::BI__builtin_matrix_transpose: {
3213
3222
const auto *MatrixTy = E->getArg(0)->getType()->getAs<ConstantMatrixType>();
0 commit comments