A newspaper report has suggested the UK government plans to "scale back and axe rail electrification projects".
During Prime Minister's Questions, Mr Cameron told Plaid Cymru MP Jonathan Edwards that ministers were committed to the London-Swansea scheme.
But he said Network Rail needed to get its costs "under control".
Mr Edwards asked: "Can you inform the house and the people of Wales whether it continues to be the policy of your government to complete [the upgrade] to Swansea by 2018 and part-fund the Valley lines?"
Mr Cameron replied: "We're absolutely committed to electrifying the Great Western Main Line to Cardiff, through to Swansea.
"We're also contributing Â£125m to the cost of the wider Valley lines electrification. It's vital that this work goes ahead.
"We do need to make sure that Network Rail gets its costs under control and has strong leadership in place and we'll make sure those things happen."
David Cameron has been challenged to say whether a project to electrify rail lines between London and Swansea will be completed by 2018.