if (isa<UndefValue>(Val))
return Vec;
+ // If we are extracting a value from a vector, then inserting it into the same
+ // place, that's the input vector:
+ // insertelt Vec, (extractelt Vec, Idx), Idx --> Vec
+ if (match(Val, m_ExtractElement(m_Specific(Vec), m_Specific(Idx))))
+ return Vec;
+
return nullptr;
}
if (match(IdxOp, m_ConstantInt(InsertedIdx)) &&
match(ScalarOp, m_ExtractElement(m_Value(ExtVecOp),
m_ConstantInt(ExtractedIdx)))) {
- // If we are extracting a value from a vector, then inserting it right
- // back into the same place, just use the input vector.
- if (ExtVecOp == VecOp && ExtractedIdx == InsertedIdx)
- return replaceInstUsesWith(IE, VecOp);
-
// TODO: Looking at the user(s) to determine if this insert is a
// fold-to-shuffle opportunity does not match the usual instcombine
// constraints. We should decide if the transform is worthy based only
define <8 x i8> @extract_insert_same_vec_and_index(<8 x i8> %in) {
; CHECK-LABEL: @extract_insert_same_vec_and_index(
-; CHECK-NEXT: [[VAL:%.*]] = extractelement <8 x i8> [[IN:%.*]], i32 5
-; CHECK-NEXT: [[VEC:%.*]] = insertelement <8 x i8> [[IN]], i8 [[VAL]], i32 5
-; CHECK-NEXT: ret <8 x i8> [[VEC]]
+; CHECK-NEXT: ret <8 x i8> [[IN:%.*]]
;
%val = extractelement <8 x i8> %in, i32 5
%vec = insertelement <8 x i8> %in, i8 %val, i32 5
define <8 x i8> @extract_insert_same_vec_and_index2(<8 x i8> %in, i32 %index) {
; CHECK-LABEL: @extract_insert_same_vec_and_index2(
-; CHECK-NEXT: [[VAL:%.*]] = extractelement <8 x i8> [[IN:%.*]], i32 [[INDEX:%.*]]
-; CHECK-NEXT: [[VEC:%.*]] = insertelement <8 x i8> [[IN]], i8 [[VAL]], i32 [[INDEX]]
-; CHECK-NEXT: ret <8 x i8> [[VEC]]
+; CHECK-NEXT: ret <8 x i8> [[IN:%.*]]
;
%val = extractelement <8 x i8> %in, i32 %index
%vec = insertelement <8 x i8> %in, i8 %val, i32 %index