[llvm] r361576 - [InstSimplify] fold insertelement-of-extractelement
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 17:13:58 PDT 2019
Author: spatel
Date: Thu May 23 17:13:58 2019
New Revision: 361576
URL: http://llvm.org/viewvc/llvm-project?rev=361576&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
llvm/trunk/test/Transforms/InstSimplify/insertelement.ll
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=361576&r1=361575&r2=361576&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Thu May 23 17:13:58 2019
@@ -4016,6 +4016,12 @@ Value *llvm::SimplifyInsertElementInst(V
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;
}
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp?rev=361576&r1=361575&r2=361576&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineVectorOps.cpp Thu May 23 17:13:58 2019
@@ -884,11 +884,6 @@ Instruction *InstCombiner::visitInsertEl
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
Modified: llvm/trunk/test/Transforms/InstSimplify/insertelement.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/insertelement.ll?rev=361576&r1=361575&r2=361576&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/insertelement.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/insertelement.ll Thu May 23 17:13:58 2019
@@ -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
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
More information about the llvm-commits
mailing list