LLVM Optimization Remarks - Ofek Shilon - CppCon 2022
Why Stack Overflow recommends it
Stack Overflow users link it when explaining compiler optimization remarks such as 'clobbered by call' and how to read Clang's optimization record output.
Recommended by 2 people across 2 different months, 2023 to 2023.
What it is
A CppCon 2022 talk by Ofek Shilon on using Clang's optimization remarks and the opt-viewer tool to find why the compiler missed optimizations. About half the talk walks through real examples, mostly escape-analysis and alias-analysis problems, and it briefly compares other compilers and languages.
What people said
Recommends viraltaco_ · 2023-02 · Stack Overflow · on “Is iterating inside a vector slower than accessing indices with a for loop?”
In layman's terms "clobbered by call" refers to "dereferencing a pointer to an object that is visible outside the current scope". I recommend this cppcon talk [this video] to get a better understanding.
Recommends Ofek Shilon · 2023-03 · Stack Overflow · on “How to use the output clang++ -fsave-optimization-record command?”
The official tool to handle these yamls is called opt-viewer and was developed by Adam Nemet from Apple. It is thinly documented here [LINK] but the best intro to it is still this 2016 talk [LINK] . fdiagnostics-show-hotness is used to enrich the same yamls with PGO data. It is a suite of python scripts, processing the generated yaml s into htmls of the compiled sources with the optimization remarks as inline annotations: [LINK] The optimization remarks themselves are essentially internal logs of various optimization passes (not all), which typically carry meaning only to pass maintainers. My personal experience with the tool left me wanting more, and so I set out to improve it and came up w
Cites James Smith · 2023-01 · Stack Overflow · on “Write numpy einsum operation as eigen tensors”
Minimum Working Example Here's a working example. See godbolt.org [LINK] to run the code. #include <Eigen/Dense> #include <unsupported/Eigen/CXX11/Tensor> int main() { // Setup tensors Eigen::Tensor<double, 3> U(2, 2, 136); Eigen::Tensor<double, 3> L(2, 2, 136); // Fill with random vars U.setRandom(); L.setRandom(); // Create a vector of dimension pairs you want to contract over // Since j is the second index in the second tensor (U) we specify index 1, since j is // the first index for the second tensor (L), we specify index 0. Eigen::array<Eigen::IndexPair<int>, 1> contraction_dims = {Eigen::IndexPair<int>(1,0)}; // Perform contraction and save result Eigen::Tensor<double, 3> result = U.co