This was added to GMP 6.2 and something similar would be useful to have in MPIR, too.
For the changes related to this see https://gmplib.org/repo/gmp-6.2/log?rev=pkg , you should be able to install this with a name change from gmp->mpir (ideally installing a copy as gmp.pc if --enable-gmp-compat is active).