This is a work-in-progress related to PR38754 , uploaded for visibility rather than review.
This patch is ugly because the behaviour exposed by the patch is ugly. If you disable placeDbgValues (topic of ), the currently semi-legitimate assumption of collectDebugValues (that DBG_VALUEs always follow the values definition) is eliminated, meaning DBG_VALUEs of a vreg can be in any BB in the function.
On the whole this is what we want IMHO, because that might be the debug-model of the program. However, we get a crash in MachineSink if it tries to sink a DBG_VALUE in front of the value-definition (maybe an un-related use-before-def bug), and a variety of infinite loops if DBG_VALUEs are sunk out of other BBs.
These are all matters that can be considered and fixed, they've just never been problems because placeDbgValues has squashed any kind of complicated DBG_VALUE layout. I've uploaded this patch because it allows clang/llvm to compile itself, might be a starting point for making other improvements. I've also only tested it with D54716 reducing the amount of code that uses collectDebugValues.