(if + past perfect, ... would + have + past participle)
If I had gone to bed early, I would have caught the train.
If clause and main clause
We use the past perfect in the if-clause of a third conditional sentence to talk about an imaginary or hypothetical situation in the past, and we use would have, could have or might have + past participle in the main clause to talk about the result or consequence of that imaginary situation.
If you had come to class more often, you would have passed the test.
If he hadn’t taken his helmet, he could have died.
If the jacket had been a bit cheaper, I might have bought it.
Comma
As with all conditional types, we use a comma after the if–clause when it goes at the beginning of the sentence, but we don’t use a comma when the if-clause goes at the end.
If I hadn’t overslept, I wouldn’t have been late.
I wouldn’t have been late if I hadn’t overslept.
Unless
We can also use unless in conditional sentences to mean if … (not)
I wouldn’t have arrived on time unless I had taken a taxi.
I wouldn’t have arrived on time if I hadn’t taken a taxi.