1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

[ConstantFold] fix inconsistent handling of extractelement with undef index (PR42689)

Any constant other than zero was already folded to undef if the index is undef.
https://bugs.llvm.org/show_bug.cgi?id=42689

llvm-svn: 374729
This commit is contained in:
Sanjay Patel 2019-10-13 17:34:08 +00:00
parent 048e400ca3
commit 072fec99fc
2 changed files with 4 additions and 7 deletions

View File

@ -787,12 +787,9 @@ Constant *llvm::ConstantFoldSelectInstruction(Constant *Cond,
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)) {

View File

@ -38,7 +38,7 @@ define <4 x i64> @insertelement_undef() {
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