Skip to content

Commit d6f7858

Browse files
committed
Revert "Add hook to limit intrinsic use"
This reverts commit aafed97.
1 parent aafed97 commit d6f7858

File tree

4 files changed

+11
-52
lines changed

4 files changed

+11
-52
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,21 +2937,12 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
29372937
&getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad())
29382938
BuiltinID = mutateLongDoubleBuiltin(BuiltinID);
29392939

2940-
const unsigned BuiltinIDIfEmitIntrinsics = [&] {
2941-
// If the builtin has been declared explicitly with an assembler label,
2942-
// disable the specialized emitting below. Ideally we should communicate the
2943-
// rename in IR, or at least avoid generating the intrinsic calls that are
2944-
// likely to get lowered to the renamed library functions.
2945-
if (FD->hasAttr<AsmLabelAttr>())
2946-
return 0U;
2947-
2948-
// If the target requests not to use intrinsics for a builtin, disable the
2949-
// specialized emitting below.
2950-
if (!getTargetHooks().shouldUseIntrinsicsForBuiltin(BuiltinID))
2951-
return 0U;
2952-
2953-
return BuiltinID;
2954-
}();
2940+
// If the builtin has been declared explicitly with an assembler label,
2941+
// disable the specialized emitting below. Ideally we should communicate the
2942+
// rename in IR, or at least avoid generating the intrinsic calls that are
2943+
// likely to get lowered to the renamed library functions.
2944+
const unsigned BuiltinIDIfNoAsmLabel =
2945+
FD->hasAttr<AsmLabelAttr>() ? 0 : BuiltinID;
29552946

29562947
std::optional<bool> ErrnoOverriden;
29572948
// ErrnoOverriden is true if math-errno is overriden via the
@@ -3044,7 +3035,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
30443035
ConstWithoutErrnoOrExceptions && ErrnoOverridenToFalseWithOpt;
30453036
}
30463037
if (GenerateIntrinsics) {
3047-
switch (BuiltinIDIfEmitIntrinsics) {
3038+
switch (BuiltinIDIfNoAsmLabel) {
30483039
case Builtin::BIacos:
30493040
case Builtin::BIacosf:
30503041
case Builtin::BIacosl:
@@ -3524,7 +3515,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
35243515
}
35253516
};
35263517

3527-
switch (BuiltinIDIfEmitIntrinsics) {
3518+
switch (BuiltinIDIfNoAsmLabel) {
35283519
default: break;
35293520
case Builtin::BI__builtin___CFStringMakeConstantString:
35303521
case Builtin::BI__builtin___NSStringMakeConstantString:
@@ -3654,7 +3645,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
36543645
case Builtin::BI__builtin_ctzl:
36553646
case Builtin::BI__builtin_ctzll:
36563647
case Builtin::BI__builtin_ctzg: {
3657-
bool HasFallback = BuiltinIDIfEmitIntrinsics == Builtin::BI__builtin_ctzg &&
3648+
bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_ctzg &&
36583649
E->getNumArgs() > 1;
36593650

36603651
Value *ArgValue =
@@ -3686,7 +3677,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
36863677
case Builtin::BI__builtin_clzl:
36873678
case Builtin::BI__builtin_clzll:
36883679
case Builtin::BI__builtin_clzg: {
3689-
bool HasFallback = BuiltinIDIfEmitIntrinsics == Builtin::BI__builtin_clzg &&
3680+
bool HasFallback = BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_clzg &&
36903681
E->getNumArgs() > 1;
36913682

36923683
Value *ArgValue =
@@ -4356,7 +4347,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
43564347
Ty = VecTy->getElementType();
43574348
bool IsSigned = Ty->isSignedIntegerType();
43584349
unsigned Opc;
4359-
if (BuiltinIDIfEmitIntrinsics == Builtin::BI__builtin_elementwise_add_sat)
4350+
if (BuiltinIDIfNoAsmLabel == Builtin::BI__builtin_elementwise_add_sat)
43604351
Opc = IsSigned ? llvm::Intrinsic::sadd_sat : llvm::Intrinsic::uadd_sat;
43614352
else
43624353
Opc = IsSigned ? llvm::Intrinsic::ssub_sat : llvm::Intrinsic::usub_sat;

clang/lib/CodeGen/TargetInfo.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -454,23 +454,6 @@ class TargetCodeGenInfo {
454454
initBranchProtectionFnAttributes(const TargetInfo::BranchProtectionInfo &BPI,
455455
llvm::AttrBuilder &FuncAttrs);
456456

457-
/// Returns true if an intrinsic should be emitted for a specific builtin. By
458-
/// default, this disables emitting intrinsics for (non-prefixed) sincos
459-
/// builtins, as on targets that do not set llvm::TargetSubtargetInfo::useAA()
460-
/// the intrinsics can worsen codegen.
461-
/// TODO: Remove once the intrinsic lowering works well for all targets.
462-
virtual bool shouldUseIntrinsicsForBuiltin(unsigned BuiltinID) const {
463-
switch (BuiltinID) {
464-
case Builtin::BIsincos:
465-
case Builtin::BIsincosf:
466-
case Builtin::BIsincosl:
467-
return false;
468-
default:
469-
break;
470-
}
471-
return true;
472-
}
473-
474457
protected:
475458
static std::string qualifyWindowsLibrary(StringRef Lib);
476459

clang/lib/CodeGen/Targets/AArch64.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,6 @@ class AArch64TargetCodeGenInfo : public TargetCodeGenInfo {
181181
bool wouldInliningViolateFunctionCallABI(
182182
const FunctionDecl *Caller, const FunctionDecl *Callee) const override;
183183

184-
bool shouldUseIntrinsicsForBuiltin(unsigned BuiltinID) const override {
185-
return true;
186-
}
187-
188184
private:
189185
// Diagnose calls between functions with incompatible Streaming SVE
190186
// attributes.

clang/test/CodeGen/math-libcalls.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -660,17 +660,6 @@ void foo(double *d, float f, float *fp, long double *l, int *i, const char *c) {
660660
// HAS_MAYTRAP: declare float @llvm.experimental.constrained.sinh.f32(
661661
// HAS_MAYTRAP: declare x86_fp80 @llvm.experimental.constrained.sinh.f80(
662662

663-
sincos(f, d, d); sincosf(f, fp, fp); sincosl(f, l, l);
664-
665-
// NO__ERRNO: declare void @sincos(double noundef, ptr noundef, ptr noundef) [[NOT_READNONE]]
666-
// NO__ERRNO: declare void @sincosf(float noundef, ptr noundef, ptr noundef) [[NOT_READNONE]]
667-
// NO__ERRNO: declare void @sincosl(x86_fp80 noundef, ptr noundef, ptr noundef) [[NOT_READNONE]]
668-
// HAS__ERRNO: declare void @sincos(double noundef, ptr noundef, ptr noundef) [[NOT_READNONE]]
669-
// HAS__ERRNO: declare void @sincosf(float noundef, ptr noundef, ptr noundef) [[NOT_READNONE]]
670-
// HAS__ERRNO: declare void @sincosl(x86_fp80 noundef, ptr noundef, ptr noundef) [[NOT_READNONE]]
671-
// HAS_MAYTRAP: declare void @sincos(double noundef, ptr noundef, ptr noundef) [[NOT_READNONE]]
672-
// HAS_MAYTRAP: declare void @sincosf(float noundef, ptr noundef, ptr noundef) [[NOT_READNONE]]
673-
// HAS_MAYTRAP: declare void @sincosl(x86_fp80 noundef, ptr noundef, ptr noundef) [[NOT_READNONE]]
674663

675664
sqrt(f); sqrtf(f); sqrtl(f);
676665

0 commit comments

Comments
 (0)