Skip to content

Commit f552ba6

Browse files
committed
Revert "[Clang] Extend emitUnaryBuiltin to avoid duplicate logic."
This reverts commit 5c57e6a. Reverted due to a typo in the authors name. Will recommit soon with fixed authorship.
1 parent 49f23af commit f552ba6

File tree

1 file changed

+49
-40
lines changed

1 file changed

+49
-40
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,13 @@ static Value *emitCallMaybeConstrainedFPBuiltin(CodeGenFunction &CGF,
532532

533533
// Emit a simple mangled intrinsic that has 1 argument and a return type
534534
// 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) {
538538
llvm::Value *Src0 = CGF.EmitScalarExpr(E->getArg(0));
539539

540540
Function *F = CGF.CGM.getIntrinsic(IntrinsicID, Src0->getType());
541-
return CGF.Builder.CreateCall(F, Src0, Name);
541+
return CGF.Builder.CreateCall(F, Src0);
542542
}
543543

544544
// 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,
31223122
}
31233123

31243124
case Builtin::BI__builtin_elementwise_abs: {
3125+
Value *Op0 = EmitScalarExpr(E->getArg(0));
31253126
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())
31313128
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");
31343130
else
3135-
Result = emitUnaryBuiltin(*this, E, llvm::Intrinsic::fabs, "elt.abs");
3136-
3131+
Result = Builder.CreateUnaryIntrinsic(llvm::Intrinsic::fabs, Op0, nullptr,
3132+
"elt.abs");
31373133
return RValue::get(Result);
31383134
}
31393135

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+
}
31433142

31443143
case Builtin::BI__builtin_elementwise_max: {
31453144
Value *Op0 = EmitScalarExpr(E->getArg(0));
@@ -3175,39 +3174,49 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
31753174
}
31763175

31773176
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+
}
31863186
return llvm::Intrinsic::vector_reduce_fmax;
31873187
};
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);
31903193
}
31913194

31923195
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+
}
32013205
return llvm::Intrinsic::vector_reduce_fmin;
32023206
};
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);
32063212
}
32073213

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+
}
32113220

32123221
case Builtin::BI__builtin_matrix_transpose: {
32133222
const auto *MatrixTy = E->getArg(0)->getType()->getAs<ConstantMatrixType>();

0 commit comments

Comments
 (0)