This is a reland of https://github.com/llvm/llvm-project/pull/155107 along with a fix for old gcc builds. This patch is reverted in https://github.com/llvm/llvm-project/pull/188344 due to compilation failures described in https://github.com/llvm/llvm-project/pull/155107#issuecomment-4121292756 The fix to old gcc builds is to remove `constexpr` modifiers in the original patch in 0721d8e7768c011b8cf2d4d223ca6eca3392b1f9