The 22-year-old has made one senior appearance for the Midlanders, but has played over 100 times in the English Football League on several loan deals, including the Millers.
He spent the first half of last season at Cardiff City before linking up with Blackburn Rovers in January.
Giles scored while on loan for Rotherham in a 3-0 win at the Riverside in early 2021.
Manager Chris Wilder said: "There was a lot of interest in him and it's great we've been able to bring him here.
"He's a player we know a lot about, he's young and he's an exciting talent.
"He has plenty of experience already at this level and knows the league. I think we're good fit for Ryan and we're really looking forward to working with him."
Giles's arrival follows on from the addition of Northampton Town keeper Liam Nicholls, while Blackburn Rovers captain Darragh Lenihan will join when his Rovers deal finishes at the end of June.