diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -792,6 +792,21 @@ return IC.replaceInstUsesWith(II, VectorSplat); } +static Optional instCombineSVEZip(InstCombiner &IC, + IntrinsicInst &II) { + // zip1(uzp1(A, B), uzp2(A, B)) --> A + // zip2(uzp1(A, B), uzp2(A, B)) --> B + Value *A, *B; + if (match(II.getArgOperand(0), + m_Intrinsic(m_Value(A), m_Value(B))) && + match(II.getArgOperand(1), m_Intrinsic( + m_Specific(A), m_Specific(B)))) + return IC.replaceInstUsesWith( + II, (II.getIntrinsicID() == Intrinsic::aarch64_sve_zip1 ? A : B)); + + return None; +} + Optional AArch64TTIImpl::instCombineIntrinsic(InstCombiner &IC, IntrinsicInst &II) const { @@ -835,6 +850,9 @@ case Intrinsic::aarch64_sve_sunpkhi: case Intrinsic::aarch64_sve_sunpklo: return instCombineSVEUnpack(IC, II); + case Intrinsic::aarch64_sve_zip1: + case Intrinsic::aarch64_sve_zip2: + return instCombineSVEZip(IC, II); } return None; diff --git a/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-zip.ll b/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-zip.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/AArch64/sve-intrinsic-opts-zip.ll @@ -0,0 +1,24 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt -S -instcombine < %s | FileCheck %s + +target triple = "aarch64-unknown-linux-gnu" + +define @redundant_zip_unzip( %a, %b) #0 { +; CHECK-LABEL: @redundant_zip_unzip( +; CHECK-NEXT: [[RET:%.*]] = add [[A:%.*]], [[B:%.*]] +; CHECK-NEXT: ret [[RET]] +; + %uzp1 = call @llvm.aarch64.sve.uzp1.nxv4i32( %a, %b) + %uzp2 = call @llvm.aarch64.sve.uzp2.nxv4i32( %a, %b) + %zip1 = call @llvm.aarch64.sve.zip1.nxv4i32( %uzp1, %uzp2) + %zip2 = call @llvm.aarch64.sve.zip2.nxv4i32( %uzp1, %uzp2) + %ret = add %zip1, %zip2 + ret %ret +} + +declare @llvm.aarch64.sve.uzp1.nxv4i32(, ) +declare @llvm.aarch64.sve.uzp2.nxv4i32(, ) +declare @llvm.aarch64.sve.zip1.nxv4i32(, ) +declare @llvm.aarch64.sve.zip2.nxv4i32(, ) + +attributes #0 = { "target-features"="+sve" }