So conceptually you could examine the predecessors of the exit block to see if any of them are a trivial return. That's your target block. Of the remaining predecessors, choose the one with the highest frequency that has only a single outgoing edge reaching the exit block. Change the edge to instead reach the new target block. You may have to mark it as FALLTHRU, I don't remember offhand.
Sorry to double-send: I realized I oversimplified, and now I see what you are getting at here. My diff handles two sequential ret-only blocks... but I could eliminate more RETs by generalizing to "any block ending in ret" (not just a ret-only block) followed by a "ret-only" block. And I realize now this is why my patch took the sequence of 3 ret's I mentioned down to only 2, not 1. I'll see if I can use this advice to fix it more generally. Robert
