@spatel, are you OK with this fix? If Constants are given to foldExtractExtract, this Builder call:
Value *NewExt = Builder.CreateExtractElement(Shuf, CheapExtIndex);
will end up with a Constant instead of an Instruction, causing a crash on the later cast.
We can reduce the test to something like this:
define i32 @constant_fold_crash(<4 x i32> %x) { %c = extractelement <4 x i32> <i32 16, i32 17, i32 18, i32 19>, i32 1 %d = extractelement <4 x i32> %x, i64 0 %e = add i32 %c, %d ret i32 %e }