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.)
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.)