amehsan added a comment. Maybe we already have this and I missed it. Could you add a testcase, that has the pattern you want to optimize. That will help reviewing the code, and also prevent breaking your this optimization in the future. http://reviews.llvm.org/D20017