trivial fix for PR20314

Make sure that the AddrInst is an Instruction.

llvm-svn: 213197
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index ccac40c..f2c7e64 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -2130,8 +2130,11 @@
     return true;
   }
   case Instruction::SExt: {
+    // Make sure this isn't a ConstantExpr (PR20314).
+    Instruction *SExt = dyn_cast<Instruction>(AddrInst);
+    if (!SExt) return false;
+
     // Try to move this sext out of the way of the addressing mode.
-    Instruction *SExt = cast<Instruction>(AddrInst);
     // Ask for a method for doing so.
     TypePromotionHelper::Action TPH = TypePromotionHelper::getAction(
         SExt, InsertedTruncs, TLI, PromotedInsts);