Study this example situation:
Anna and Mary are very good friends. They live in different countries and don’t see each other very often but they talk on the phone regularly.
Anna lost her phone and so they lost contact with each other as well. Mary went to London on a course, she tried to reach Anna but she couldn’t.
A week later, Anna found out that Mary was in London. She said to herself: If I had known she was in London, I would have invited her over.
We use if + Past Perfect Simple or Continuous (had + past participle / had +been + present participle) + would + have + past participle to talk about situations in the past.
eg. She decided to go stay home. She would have gone out if her friends had called.
If she had been paying attention to our conversation she would have known what we were talking about. (but she wasn’t paying attention)
Do not use would in the if – part of the sentence. We use would in the other part of the sentence.