@@ -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,
536
- const CallExpr *E ,
537
- unsigned IntrinsicID ) {
535
+ static Value *emitUnaryBuiltin(CodeGenFunction &CGF, const CallExpr *E,
536
+ unsigned IntrinsicID ,
537
+ llvm::StringRef Name = "" ) {
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);
541
+ return CGF.Builder.CreateCall(F, Src0, Name );
542
542
}
543
543
544
544
// Emit an intrinsic that has 2 operands of the same type as its result.
@@ -3122,24 +3122,25 @@ 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));
3126
3125
Value *Result;
3127
- if (Op0->getType()->isIntOrIntVectorTy())
3126
+ QualType QT = E->getArg(0)->getType();
3127
+
3128
+ if (auto *VecTy = QT->getAs<VectorType>())
3129
+ QT = VecTy->getElementType();
3130
+ if (QT->isIntegerType())
3128
3131
Result = Builder.CreateBinaryIntrinsic(
3129
- llvm::Intrinsic::abs, Op0, Builder.getFalse(), nullptr, "elt.abs");
3132
+ llvm::Intrinsic::abs, EmitScalarExpr(E->getArg(0)),
3133
+ Builder.getFalse(), nullptr, "elt.abs");
3130
3134
else
3131
- Result = Builder.CreateUnaryIntrinsic(llvm::Intrinsic::fabs, Op0, nullptr,
3132
- "elt.abs");
3133
- return RValue::get(Result);
3134
- }
3135
+ Result = emitUnaryBuiltin(*this, E, llvm::Intrinsic::fabs, "elt.abs");
3135
3136
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
3137
return RValue::get(Result);
3141
3138
}
3142
3139
3140
+ case Builtin::BI__builtin_elementwise_ceil:
3141
+ return RValue::get(
3142
+ emitUnaryBuiltin(*this, E, llvm::Intrinsic::ceil, "elt.ceil"));
3143
+
3143
3144
case Builtin::BI__builtin_elementwise_max: {
3144
3145
Value *Op0 = EmitScalarExpr(E->getArg(0));
3145
3146
Value *Op1 = EmitScalarExpr(E->getArg(1));
@@ -3174,50 +3175,40 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
3174
3175
}
3175
3176
3176
3177
case Builtin::BI__builtin_reduce_max: {
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
- }
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");
3186
3186
return llvm::Intrinsic::vector_reduce_fmax;
3187
3187
};
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);
3188
+ return RValue::get(emitUnaryBuiltin(
3189
+ *this, E, GetIntrinsicID(E->getArg(0)->getType()), "rdx.min"));
3193
3190
}
3194
3191
3195
3192
case Builtin::BI__builtin_reduce_min: {
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
- }
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");
3205
3201
return llvm::Intrinsic::vector_reduce_fmin;
3206
3202
};
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);
3212
- }
3213
3203
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);
3204
+ return RValue::get(emitUnaryBuiltin(
3205
+ *this, E, GetIntrinsicID(E->getArg(0)->getType()), "rdx.min"));
3219
3206
}
3220
3207
3208
+ case Builtin::BI__builtin_reduce_xor:
3209
+ return RValue::get(emitUnaryBuiltin(
3210
+ *this, E, llvm::Intrinsic::vector_reduce_xor, "rdx.xor"));
3211
+
3221
3212
case Builtin::BI__builtin_matrix_transpose: {
3222
3213
const auto *MatrixTy = E->getArg(0)->getType()->getAs<ConstantMatrixType>();
3223
3214
Value *MatValue = EmitScalarExpr(E->getArg(0));
0 commit comments