Fixes: https://bugs.llvm.org/show_bug.cgi?id=51841
This patch places an arbitrary limit on the size of DIExpressions that we will produce via salvaging, for performance reasons. This helps to fix a performance issue observed in the bug above, in which debug values would be salvaged hundreds of times, producing expressions with over 1000 elements and causing the compiler to hang. Limiting the size of debug values that we will produce to 128 largely fixes this issue.
It should be noted that this is not the only issue related to the bug above; InstCombine is also quadratically growing the number of debug intrinsics with each block it moves through, resulting in the number of intrinsics growing from 4561 to 70710 despite the fact that not a single one of the new intrinsics adds useful debug info. There are potential fixes for this, but I believe the problem of unlimited salvaging will still be an issue even if we smarten up InstCombine, as we can still legitimately salvage thousands of intrinsics thousands of times each before we determine that the resulting intrinsics provide no useful info. As such, I think this patch is probably a necessity that we can aim to reduce our dependence on with further changes.
IMO, "Valid" is the wrong term to use here as it suggests a correctness problem. Could I suggest "IsDesirableSalvageExpr"?