Created attachment 24135 [details] bbi-48944.ll reproducer Reproduce with: opt -S -o - bbi-48944.ll -memcpyopt Result: opt: ../include/llvm/Support/Casting.h:269: typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = llvm::PointerType, Y = llvm::Type]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed. This seems to be rather old, I've reproduced it with saved builds from July 2019.
I'm not sure if there's some enhancement potential in here, but this should prevent the crashing at least by dyn_casting instead of plain casting: https://reviews.llvm.org/rGc5a4d80fd47c
Thanks!