LLVM crashes with following IRs if compiling it with opt -instsimplify. See PR34880
@block = global [64 x [8192 x i8]] zeroinitializer, align 1 define <2 x i8*> @foo() { %1 = getelementptr inbounds [64 x [8192 x i8]], [64 x [8192 x i8]]* @block, i64 0, <2 x i64> <i64 0, i64 1>, i64 8192 ret <2 x i8*> %1 }
ConstantFolding tries to factor out the last index (8192) into the second last dimension. The code assumes the current index (8192) and the previous index (<i64 0, i64 1>) are both integer typed, but it now only checks if the current index is a ConstantInt. This patch exits early if the previous index is not a ConstantInt.