Edit: In Karpinski v The Queen  VSCA 94, Weinberg JA voiced a concern over the way R v Renzella  2 VR 88 is now being applied [at 7]:
Any accused who has been wrongly imprisoned is, of course, the victim of a grave injustice. It does not follow, however, that it is society’s duty to ameliorate that injustice by giving the accused credit for the time spent in custody when he is sentenced at a later time for entirely unrelated offending.
s 18 Sentencing Act 1991 requires pre-sentence detention to be reckoned in calculating the appropriate term of imprisonment to be awarded.
Time in custody for more than one reason (for example, awaiting trial while also serving a sentence for something else) can also be reckoned as time served. (When s 18 of the Sentencing Act did not allow for this, the common law still did: R v Renzalla  2 VR 88). Even when ‘doubly warranted’ a sentencing court can take some or all of that period of incarceration into account.
The use of custody that’s wholly unconnected to the offences which the accused is being sentenced for is less clear. Callaway JA said in R v Kotsmann  2 VR 123 [at 137],
There can be no question of a person on remand who is subsequently acquitted acquiring a kind of bank balance on which to draw in relation to subsequent offences unconnected with the reason for custody …
It wouldn’t be a good look if a person who had been charged and acquitted, but who had spent 18 months awaiting their trial, were able to cash in on their ‘credit’. They’d probably be foolish if they didn’t take advantage of the ‘debt’ owed them by the State and commit some free crimes.
The weight of authority favours the existence of a discretion to take into account unrelated time in custody, depending on the circumstances of the case. The exercise is not mathematical, or confined to a strict ratio: Maxwell P and Weinberg JA in their joint judgment of Warwick v R  VSCA 166 [at 10]. And the Court in Warwick‘s case suggested this discretion could change in the future [at 18 and 19]:
It does seem to us, as we raised in the course of argument, that there may be a question for investigation as to the basis on which detention of that kind is thought to be relevant when the person comes to be sentenced for quite unrelated matters. In so saying, we recognise that there is obvious injustice where a person has served a term of imprisonment which he or she should not have served. In other jurisdictions, that injustice is addressed by formal procedures for compensation for such periods. No such system exists in this State.
The question which may require investigation is whether a form of judicial compensation, by way of sentence discounts in relation to other matters, is the appropriate way to deal with this species of injustice. As we have said, the law in Victoria as it stands is that it is properly dealt with in that way. As Weinberg JA pointed out, however, the logic of this approach would seem to be that ‘unjust’ imprisonment should always stand to a person’s credit, however long after the event it is sought to be called in aid. As we say, that is a question for another day.