llvm.org GIT mirror llvm / 4888407
[InstSimplify] fold insertelement-of-extractelement This was partly handled in InstCombine (only the constant index case), so delete that and zap it more generally in InstSimplify. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361576 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel 3 months ago
3 changed file(s) with 8 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
40154015 if (isa(Val))
40164016 return Vec;
40174017
4018 // If we are extracting a value from a vector, then inserting it into the same
4019 // place, that's the input vector:
4020 // insertelt Vec, (extractelt Vec, Idx), Idx --> Vec
4021 if (match(Val, m_ExtractElement(m_Specific(Vec), m_Specific(Idx))))
4022 return Vec;
4023
40184024 return nullptr;
40194025 }
40204026
883883 if (match(IdxOp, m_ConstantInt(InsertedIdx)) &&
884884 match(ScalarOp, m_ExtractElement(m_Value(ExtVecOp),
885885 m_ConstantInt(ExtractedIdx)))) {
886 // If we are extracting a value from a vector, then inserting it right
887 // back into the same place, just use the input vector.
888 if (ExtVecOp == VecOp && ExtractedIdx == InsertedIdx)
889 return replaceInstUsesWith(IE, VecOp);
890
891886 // TODO: Looking at the user(s) to determine if this insert is a
892887 // fold-to-shuffle opportunity does not match the usual instcombine
893888 // constraints. We should decide if the transform is worthy based only
5151
5252 define <8 x i8> @extract_insert_same_vec_and_index(<8 x i8> %in) {
5353 ; CHECK-LABEL: @extract_insert_same_vec_and_index(
54 ; CHECK-NEXT: [[VAL:%.*]] = extractelement <8 x i8> [[IN:%.*]], i32 5
55 ; CHECK-NEXT: [[VEC:%.*]] = insertelement <8 x i8> [[IN]], i8 [[VAL]], i32 5
56 ; CHECK-NEXT: ret <8 x i8> [[VEC]]
54 ; CHECK-NEXT: ret <8 x i8> [[IN:%.*]]
5755 ;
5856 %val = extractelement <8 x i8> %in, i32 5
5957 %vec = insertelement <8 x i8> %in, i8 %val, i32 5
6260
6361 define <8 x i8> @extract_insert_same_vec_and_index2(<8 x i8> %in, i32 %index) {
6462 ; CHECK-LABEL: @extract_insert_same_vec_and_index2(
65 ; CHECK-NEXT: [[VAL:%.*]] = extractelement <8 x i8> [[IN:%.*]], i32 [[INDEX:%.*]]
66 ; CHECK-NEXT: [[VEC:%.*]] = insertelement <8 x i8> [[IN]], i8 [[VAL]], i32 [[INDEX]]
67 ; CHECK-NEXT: ret <8 x i8> [[VEC]]
63 ; CHECK-NEXT: ret <8 x i8> [[IN:%.*]]
6864 ;
6965 %val = extractelement <8 x i8> %in, i32 %index
7066 %vec = insertelement <8 x i8> %in, i8 %val, i32 %index