[llvm] r374729 - [ConstantFold] fix inconsistent handling of extractelement with undef index (PR42689)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 13 10:34:08 PDT 2019
Author: spatel
Date: Sun Oct 13 10:34:08 2019
New Revision: 374729
URL: http://llvm.org/viewvc/llvm-project?rev=374729&view=rev
Log:
[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
Modified:
llvm/trunk/lib/IR/ConstantFold.cpp
llvm/trunk/test/Transforms/ConstProp/InsertElement.ll
Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=374729&r1=374728&r2=374729&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Sun Oct 13 10:34:08 2019
@@ -787,12 +787,9 @@ Constant *llvm::ConstantFoldSelectInstru
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)) {
Modified: llvm/trunk/test/Transforms/ConstProp/InsertElement.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ConstProp/InsertElement.ll?rev=374729&r1=374728&r2=374729&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ConstProp/InsertElement.ll (original)
+++ llvm/trunk/test/Transforms/ConstProp/InsertElement.ll Sun Oct 13 10:34:08 2019
@@ -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
More information about the llvm-commits
mailing list