diff options
author | Noah Goldstein <goldstein.w.n@gmail.com> | 2024-07-29 20:02:28 +0800 |
---|---|---|
committer | Noah Goldstein <goldstein.w.n@gmail.com> | 2024-07-30 00:56:53 +0800 |
commit | 67fb7c34f11df03ac359571dd4d503a36e06275e (patch) | |
tree | d16bc25882a6b1bd8bb616b6115e0a36db780a34 /llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | |
parent | e65882fec9689b2232575530bab0776d7c303dae (diff) | |
download | llvm-67fb7c34f11df03ac359571dd4d503a36e06275e.zip llvm-67fb7c34f11df03ac359571dd4d503a36e06275e.tar.gz llvm-67fb7c34f11df03ac359571dd4d503a36e06275e.tar.bz2 |
[TLI] Add support for inferring attr `cold` on `exit`/`abort`
`abort` can be assumed always cold and assume non-zero `exit` status
as a `cold` path as well.
Closes #101003
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp index 92c4426..4100471 100644 --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -3729,6 +3729,17 @@ Value *LibCallSimplifier::optimizePuts(CallInst *CI, IRBuilderBase &B) { return nullptr; } +Value *LibCallSimplifier::optimizeExit(CallInst *CI) { + + // Mark 'exit' as cold if its not exit(0) (success). + const APInt *C; + if (!CI->hasFnAttr(Attribute::Cold) && + match(CI->getArgOperand(0), m_APInt(C)) && !C->isZero()) { + CI->addFnAttr(Attribute::Cold); + } + return nullptr; +} + Value *LibCallSimplifier::optimizeBCopy(CallInst *CI, IRBuilderBase &B) { // bcopy(src, dst, n) -> llvm.memmove(dst, src, n) return copyFlags(*CI, B.CreateMemMove(CI->getArgOperand(1), Align(1), @@ -4084,6 +4095,9 @@ Value *LibCallSimplifier::optimizeCall(CallInst *CI, IRBuilderBase &Builder) { case LibFunc_vfprintf: case LibFunc_fiprintf: return optimizeErrorReporting(CI, Builder, 0); + case LibFunc_exit: + case LibFunc_Exit: + return optimizeExit(CI); default: return nullptr; } |