[llvm] Use DIExpression::foldConstantMath() at the result of an appendOpsToArg() (PR #71721)

Stephen Tozer via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 22 06:59:34 PDT 2024


SLTozer wrote:

Looking at some compile time stats as-of the most recent rebase: this patch stack has a geomean +0.32% to [compile time](http://llvm-compile-time-tracker.com/compare.php?from=1f01c580444ea2daef67f95ffc5fde2de5a37cec&to=b4d7e1cb2a81c465afe3d1cdae5712b393cc1ce9&stat=instructions%3Au) at ReleaseLTO-g, in return for -0.01% [file size](http://llvm-compile-time-tracker.com/compare.php?from=1f01c580444ea2daef67f95ffc5fde2de5a37cec&to=b4d7e1cb2a81c465afe3d1cdae5712b393cc1ce9&stat=size-file). Looking at the specific projects, it looks as though the best cost-benefit ratio comes from tramp3d-v4 (which probably generates a higher proportion of constant-foldable expressions), which has +0.53% compile time for -0.05% file size; I think that's still not a _great_ ratio. I'd be interested to see if there are any heuristics that could be applied to reduce the compile time increase.

A few suggestions that might improve performance:
- Move this from appendOpsToArg to salvageDebugInfoImpl - that's where I'd guess all of the foldable expressions are coming from, and in addition to being called less often, there's contextual information there that could help simplify further, such as...
- Only check for a constant foldable expression if we have just salvaged a foldable operation with a constant operand - any other salvage operation can't have turned a non-foldable expression to a foldable one.
- Instead of performing this on every DIExpression that gets updated, which in many cases will actually be performing this on the same DIExpression repeatedly and returning the same result each time, you could manually track the users of each updated DIExpression, then for each DIExpression try to constant-fold it _once_ and update each user to point to the new DIExpression.

I think that simplifying DIExpressions _is_ something that should be pursued, so I apologize for adding to the workload of actually implementing it!

https://github.com/llvm/llvm-project/pull/71721


More information about the llvm-commits mailing list