Yup, it's used widely in end-of-life care here in the UK (I remember my mum once saying to me, when we were discussing euthanasia, that there's no doctor in the country who hasn't 'accidentally' given a little too much diamorphine to someone who was on the verge of death and in pain).
It's useful, but I imagine it's tainted in the US by the association with street heroin - somewhat curiously, since fentanyl apparently hasn't been tainted by its recreational associations.
I've no idea how often it is done with the intent to end life, but doctors are legally allowed to give doses of medication that may hasten death, providing their intention is only to relieve pain and suffering - https://en.wikipedia.org/wiki/R_v_Adams_(1957)
It can be argued[1] that only doses that are virtually certain to cause death lead to liability for the death, so no doubt there is some overlap between doses given to relieve pain and those that quicken death.
Diamorphine is also sometimes used for labour pain.[2]
Indeed, you're referring to the doctrine of double effect (which the linked Wikipedia article on R v Adams mentions).
That said, I don't think "[only] doses that are virtually certain to cause death lead to liability for the death" is correct. You had it right the first time: the relevant fact is not whether it's likely or even certain to cause death, but rather whether causing death is the primary intention. (I'm not a lawyer, though, I'm just speaking on the basis of my knowledge as a lay person.)
It's useful, but I imagine it's tainted in the US by the association with street heroin - somewhat curiously, since fentanyl apparently hasn't been tainted by its recreational associations.