Evan pointed out that folding sext to zext may not be correct
if the zext is not legal.

llvm-svn: 50368
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index dc59006..28f32d3 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2888,7 +2888,8 @@
   }
   
   // fold (sext x) -> (zext x) if the sign bit is known zero.
-  if (DAG.SignBitIsZero(N0))
+  if ((!AfterLegalize || TLI.isOperationLegal(ISD::ZERO_EXTEND, VT)) &&
+      DAG.SignBitIsZero(N0))
     return DAG.getNode(ISD::ZERO_EXTEND, VT, N0);
   
   return SDOperand();