mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-03-07 11:59:09 +00:00
[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. llvm-svn: 361576
This commit is contained in:
parent
4c5bf0241a
commit
80789faf83
@ -4016,6 +4016,12 @@ Value *llvm::SimplifyInsertElementInst(Value *Vec, Value *Val, Value *Idx,
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -884,11 +884,6 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
|
||||
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
|
||||
|
@ -52,9 +52,7 @@ define <4 x i32> @PR1286(<4 x i32> %A) {
|
||||
|
||||
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
|
||||
@ -63,9 +61,7 @@ define <8 x i8> @extract_insert_same_vec_and_index(<8 x i8> %in) {
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user