Constant *llvm::ConstantFoldExtractElementInstruction(Constant *Val,
Constant *Idx) {
- if (isa<UndefValue>(Val)) // ee(undef, x) -> undef
- return UndefValue::get(Val->getType()->getVectorElementType());
- if (Val->isNullValue()) // ee(zero, x) -> zero
- return Constant::getNullValue(Val->getType()->getVectorElementType());
- // ee({w,x,y,z}, undef) -> undef
- if (isa<UndefValue>(Idx))
+ // extractelt undef, C -> undef
+ // extractelt C, undef -> undef
+ if (isa<UndefValue>(Val) || isa<UndefValue>(Idx))
return UndefValue::get(Val->getType()->getVectorElementType());
if (ConstantInt *CIdx = dyn_cast<ConstantInt>(Idx)) {
define i64 @extract_undef_index_from_zero_vec() {
; CHECK-LABEL: @extract_undef_index_from_zero_vec(
-; CHECK-NEXT: ret i64 0
+; CHECK-NEXT: ret i64 undef
;
%E = extractelement <2 x i64> zeroinitializer, i64 undef
ret i64 %E