This is the updated patch for reverted patch "r216066 - Optimize ZERO_EXTEND and SIGN_EXTEND in both SelectionDAG Builder and type".
The solution of r216066 slowed down a huge case reported by Rafael, so it was reverted. The root cause is CopyValueToVirtualRegisters in SelectionDAGBuilder is called too many times in back-end, and my original algorithm was to check all users for a value, so the time complexity could increase from O(n) to O(n^2) specifically for this feature.
The new solution tries to do early decision making before real ISEL stage, and get the sext/zext preferences stored into FuncInfo. We can do this because deciding preferred sext/zext doesn't depend on SDNode but LLVM IR. This way, we will be able to calculate the info once and use it many times in real ISEL stage.
With this patch, we won't see any slowdown for the test case at https://drive.google.com/file/d/0B7iRtublysV6RVpFUGNxaUcwc1E/edit?usp=sharing, which is a huge one.