Bush gained no votes over Iraq. He in fact lost enough votes to nearly lose the election.
The effect of Iraq was much more immediate than the broader foreign policy question. It's possible to ask what would have happened had Iraq gone better, while to ask who would have won had there been no 9/11 is to get deep into counterfactual history and fantasy. But if we're asking about longer term trends, Bush's security uptick may not be a more lasting gain to the party than his losses of votes over problems in Iraq. Some of those who went with Bush because of concerns over terrorism aren't going to be convinced Republicans in later elections, while some of those who voted against him because of the war may be lost to the party.
But I don't have a crystal ball and can't predict that. The net effects of the war will depend on what happens over the next four years and how Americans react to it. One thing, though: it's hard to tell how many people swung to Bush because it looked to them like the Iraq war meant that he was serious about terrorism. Doubtless he lost some votes because of the problems on the ground there, but I don't think that's the whole story.