Skip to content

Commit

Permalink
Check for incompatible attributes before setting optsize
Browse files Browse the repository at this point in the history
  • Loading branch information
aneshlya committed Jan 21, 2025
1 parent 839feab commit d62af6b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/func.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2011-2024, Intel Corporation
Copyright (c) 2011-2025, Intel Corporation
SPDX-License-Identifier: BSD-3-Clause
*/
Expand Down Expand Up @@ -299,6 +299,18 @@ void Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function, Sour
function->addFnAttr("target-features", "+simd128");
}

// This attribute is required for LoopUnroll passes when -O1
if (g->opt.level == 1) {
#if ISPC_LLVM_VERSION >= ISPC_LLVM_18_1
if ((!function->hasFnAttribute(llvm::Attribute::OptimizeNone)) &&
(!function->hasFnAttribute(llvm::Attribute::OptimizeForDebugging)))
#else
if (!function->hasFnAttribute(llvm::Attribute::OptimizeNone))
#endif
{
function->addFnAttr(llvm::Attribute::OptimizeForSize);
}
}
g->target->markFuncWithTargetAttr(function);
const FunctionType *type = CastType<FunctionType>(sym->type);
Assert(type != nullptr);
Expand Down
5 changes: 1 addition & 4 deletions src/ispc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2290,10 +2290,7 @@ Target::Target(Arch arch, const char *cpu, ISPCTarget ispc_target, PICLevel picL
for (auto const &f_attr : m_funcAttributes) {
fattrBuilder->addAttribute(f_attr.first, f_attr.second);
}
// This attribute is required for LoopUnroll passes
if (g->opt.level == 1) {
fattrBuilder->addAttribute(llvm::Attribute::OptimizeForSize);
}

this->m_tf_attributes = fattrBuilder;

Assert(this->m_vectorWidth <= ISPC_MAX_NVEC);
Expand Down

0 comments on commit d62af6b

Please sign in to comment.