4 ms·
Notably, function specialization optimization has been finally enabled by default, although it still seems to only be capable of constant propagating variables
by camel-cdr 4y ago
Notably, function specialization optimization has been finally enabled by default, although it still seems to only be capable of constant propagating variables of register size [1].
The heuristics are, understandably so, somewhat conservative [2], and I presume there are some projects that could benefit from enabling `-mllvm -funcspec-for-literal-constant`, raising `-mllvm funcspec-max-clones=3` ad lowering `-mllvm -funcspec-min-function-size=100`.
[1] https://godbolt.org/z/jKo7K3jPd https://godbolt.org/z/jKo7K3jPd
[2] https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp#L69 https://github.com/llvm/llvm-project/blob/main/llvm/lib/Tran...
- pitaj 4y agoI wonder if function specialization will help Rust, C++, etc as much as it will benefit C.
- celrod 4y agoI don't think it is likely to help C++, as templates and `auto` arguments (in C++20) were already specializing. These probably cover most of the cases you'd encounter there. I'm less familiar with Rust, but I'd have assumed trait implementations specialize there as well.
- josephg 4y ago> I'm less familiar with Rust, but I'd have assumed trait implementations specialize there as well. Yeah - as I understand it, traits + generics in rust monomorphize basically everything. If anything, for rust I want the compiler to learn to do the opposite of this optimization. I'd like the compiler to be able to emit code which uses dynamic dispatch instead of monomorphization when optimizing for code size, or in cold functions. Monomorphization makes the rust compiler slower and rust binaries larger. Outside of hot loops, its often not worth it. You can change this manually by rewriting rust functions to take dyn function pointers instead of <F: Fn> generic arguments. But I'd prefer the compiler to make that choice for me automatically based on PGO or from -Oz.
- pertymcpert 4y agoLLVM can outline code from across multiple functions at -Oz which could help.