Index: lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- lib/CodeGen/CodeGenPrepare.cpp +++ lib/CodeGen/CodeGenPrepare.cpp @@ -2759,7 +2759,7 @@ // the original IR value was tossed in favor of a constant back when // the AddrMode was created we need to bail out gracefully if widths // do not match instead of extending it. - Instruction *I = dyn_cast(Result); + Instruction *I = dyn_cast_or_null(Result); if (I && (Result != AddrMode.BaseReg)) I->eraseFromParent(); return false; Index: test/CodeGen/X86/codegen-prepare-crash.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/codegen-prepare-crash.ll @@ -0,0 +1,14 @@ +; RUN: llc < %s +target triple = "x86_64-unknown-linux-gnu" + +@g = external global [10 x i32] + +define void @f(i32 %u) { + %1 = add i32 %u, 4 + br label %P.Proc8.exit + +P.Proc8.exit: + %valueindex35.i = getelementptr [10 x i32]* @g, i32 0, i32 %1 + store i32 %u, i32* %valueindex35.i + ret void +}