[PATCH] D102699: [InstSimplify] Properly constrain {insert,extract}_subvector intrinsic fold
Joe Ellis via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 18 10:08:24 PDT 2021
joechrisellis updated this revision to Diff 346206.
joechrisellis added a comment.
Remove unused `%pg` variable in test.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102699/new/
https://reviews.llvm.org/D102699
Files:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/insert-vector.ll
Index: llvm/test/Transforms/InstSimplify/insert-vector.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/insert-vector.ll
+++ llvm/test/Transforms/InstSimplify/insert-vector.ll
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instsimplify -S | FileCheck %s
-define <vscale x 16 x i8> @redundant_extract_insert_chain(<vscale x 16 x i1> %pg, <vscale x 16 x i8> %x) {
+define <vscale x 16 x i8> @redundant_extract_insert_chain(<vscale x 16 x i8> %x) {
; CHECK-LABEL: @redundant_extract_insert_chain(
; CHECK-NEXT: ret <vscale x 16 x i8> [[X:%.*]]
;
@@ -10,8 +10,8 @@
ret <vscale x 16 x i8> %inserted
}
-define <vscale x 16 x i8> @non_redundant_extract_insert_chain(<vscale x 16 x i1> %pg, <vscale x 32 x i8> %x) {
-; CHECK-LABEL: @non_redundant_extract_insert_chain(
+define <vscale x 16 x i8> @non_redundant_extract_insert_chain_0(<vscale x 32 x i8> %x) {
+; CHECK-LABEL: @non_redundant_extract_insert_chain_0(
; CHECK-NEXT: [[EXTRACTED:%.*]] = call <32 x i8> @llvm.experimental.vector.extract.v32i8.nxv32i8(<vscale x 32 x i8> [[X:%.*]], i64 0)
; CHECK-NEXT: [[INSERTED:%.*]] = call <vscale x 16 x i8> @llvm.experimental.vector.insert.nxv16i8.v32i8(<vscale x 16 x i8> undef, <32 x i8> [[EXTRACTED]], i64 0)
; CHECK-NEXT: ret <vscale x 16 x i8> [[INSERTED]]
@@ -21,6 +21,17 @@
ret <vscale x 16 x i8> %inserted
}
+define <vscale x 16 x i8> @non_redundant_extract_insert_chain_1(<vscale x 16 x i8> %x, <vscale x 16 x i8> %y) {
+; CHECK-LABEL: @non_redundant_extract_insert_chain_1(
+; CHECK-NEXT: [[EXTRACTED:%.*]] = call <32 x i8> @llvm.experimental.vector.extract.v32i8.nxv16i8(<vscale x 16 x i8> [[X:%.*]], i64 0)
+; CHECK-NEXT: [[INSERTED:%.*]] = call <vscale x 16 x i8> @llvm.experimental.vector.insert.nxv16i8.v32i8(<vscale x 16 x i8> [[Y:%.*]], <32 x i8> [[EXTRACTED]], i64 0)
+; CHECK-NEXT: ret <vscale x 16 x i8> [[INSERTED]]
+;
+ %extracted = call <32 x i8> @llvm.experimental.vector.extract.v32i8.nxv16i8(<vscale x 16 x i8> %x, i64 0)
+ %inserted = call <vscale x 16 x i8> @llvm.experimental.vector.insert.nxv16i8.v32i8(<vscale x 16 x i8> %y, <32 x i8> %extracted, i64 0)
+ ret <vscale x 16 x i8> %inserted
+}
+
declare <32 x i8> @llvm.experimental.vector.extract.v32i8.nxv16i8(<vscale x 16 x i8>, i64)
declare <32 x i8> @llvm.experimental.vector.extract.v32i8.nxv32i8(<vscale x 32 x i8>, i64)
declare <vscale x 16 x i8> @llvm.experimental.vector.insert.nxv16i8.v32i8(<vscale x 16 x i8>, <32 x i8>, i64)
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -5734,16 +5734,19 @@
return nullptr;
}
case Intrinsic::experimental_vector_insert: {
+ Value *Vec = Call->getArgOperand(0);
Value *SubVec = Call->getArgOperand(1);
Value *Idx = Call->getArgOperand(2);
Type *ReturnType = F->getReturnType();
- // (insert_vector _, (extract_vector X, 0), 0) -> X
+ // (insert_vector Y, (extract_vector X, 0), 0) -> X
+ // where: Y is X, or Y is undef
unsigned IdxN = cast<ConstantInt>(Idx)->getZExtValue();
Value *X = nullptr;
if (match(SubVec, m_Intrinsic<Intrinsic::experimental_vector_extract>(
m_Value(X), m_Zero())) &&
- IdxN == 0 && X->getType() == ReturnType)
+ (Q.isUndefValue(Vec) || Vec == X) && IdxN == 0 &&
+ X->getType() == ReturnType)
return X;
return nullptr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102699.346206.patch
Type: text/x-patch
Size: 3611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210518/0fc32312/attachment.bin>
More information about the llvm-commits
mailing list