diff options
author | 2021-04-15 08:12:11 +0000 | |
---|---|---|
committer | 2021-04-20 10:02:49 +0000 | |
commit | effacc15999dde16de3e991f861769bc899aa910 (patch) | |
tree | fb44cc1a221232b915d576dbc656fd0a3df3e04f | |
parent | [AArch64][SVE][InstCombine] Replace last{a,b} intrinsics with extracts... (diff) | |
download | llvm-project-effacc15999dde16de3e991f861769bc899aa910.tar.gz llvm-project-effacc15999dde16de3e991f861769bc899aa910.tar.bz2 llvm-project-effacc15999dde16de3e991f861769bc899aa910.zip |
[AArch64] Constant fold sve_convert_from_svbool(zero) to zero
Co-authored-by: Paul Walker <paul.walker@arm.com>
Differential Revision: https://reviews.llvm.org/D100463
3 files changed, 45 insertions, 17 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index d326af554e5a..cd65e6369567 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -41,6 +41,7 @@ #include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" #include "llvm/IR/Intrinsics.h" +#include "llvm/IR/IntrinsicsAArch64.h" #include "llvm/IR/IntrinsicsAMDGPU.h" #include "llvm/IR/IntrinsicsARM.h" #include "llvm/IR/IntrinsicsWebAssembly.h" @@ -1486,6 +1487,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) { case Intrinsic::arm_mve_vctp16: case Intrinsic::arm_mve_vctp32: case Intrinsic::arm_mve_vctp64: + case Intrinsic::aarch64_sve_convert_from_svbool: // WebAssembly float semantics are always known case Intrinsic::wasm_trunc_signed: case Intrinsic::wasm_trunc_unsigned: @@ -2847,20 +2849,10 @@ static Constant *ConstantFoldScalarCall(StringRef Name, return nullptr; } -static Constant *ConstantFoldVectorCall(StringRef Name, - Intrinsic::ID IntrinsicID, - VectorType *VTy, - ArrayRef<Constant *> Operands, - const DataLayout &DL, - const TargetLibraryInfo *TLI, - const CallBase *Call) { - // Do not iterate on scalable vector. The number of elements is unknown at - // compile-time. - if (isa<ScalableVectorType>(VTy)) - return nullptr; - - auto *FVTy = cast<FixedVectorType>(VTy); - +static Constant *ConstantFoldFixedVectorCall( + StringRef Name, Intrinsic::ID IntrinsicID, FixedVectorType *FVTy, + ArrayRef<Constant *> Operands, const DataLayout &DL, + const TargetLibraryInfo *TLI, const CallBase *Call) { SmallVector<Constant *, 4> Result(FVTy->getNumElements()); SmallVector<Constant *, 4> Lane(Operands.size()); Type *Ty = FVTy->getElementType(); @@ -2977,6 +2969,24 @@ static Constant *ConstantFoldVectorCall(StringRef Name, return ConstantVector::get(Result); } +static Constant *ConstantFoldScalableVectorCall( + StringRef Name, Intrinsic::ID IntrinsicID, ScalableVectorType *SVTy, + ArrayRef<Constant *> Operands, const DataLayout &DL, + const TargetLibraryInfo *TLI, const CallBase *Call) { + switch (IntrinsicID) { + case Intrinsic::aarch64_sve_convert_from_svbool: { + auto *Src = dyn_cast<Constant>(Operands[0]); + if (!Src || !Src->isNullValue()) + break; + + return ConstantInt::getFalse(SVTy); + } + default: + break; + } + return nullptr; +} + } // end anonymous namespace Constant *llvm::ConstantFoldCall(const CallBase *Call, Function *F, @@ -2990,9 +3000,15 @@ Constant *llvm::ConstantFoldCall(const CallBase *Call, Function *F, Type *Ty = F->getReturnType(); - if (auto *VTy = dyn_cast<VectorType>(Ty)) - return ConstantFoldVectorCall(Name, F->getIntrinsicID(), VTy, Operands, - F->getParent()->getDataLayout(), TLI, Call); + if (auto *FVTy = dyn_cast<FixedVectorType>(Ty)) + return ConstantFoldFixedVectorCall( + Name, F->getIntrinsicID(), FVTy, Operands, + F->getParent()->getDataLayout(), TLI, Call); + + if (auto *SVTy = dyn_cast<ScalableVectorType>(Ty)) + return ConstantFoldScalableVectorCall( + Name, F->getIntrinsicID(), SVTy, Operands, + F->getParent()->getDataLayout(), TLI, Call); return ConstantFoldScalarCall(Name, F->getIntrinsicID(), Ty, Operands, TLI, Call); diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/AArch64/aarch64-sve-convert-from-svbool.ll b/llvm/test/Transforms/InstSimplify/ConstProp/AArch64/aarch64-sve-convert-from-svbool.ll new file mode 100644 index 000000000000..c5115e46175a --- /dev/null +++ b/llvm/test/Transforms/InstSimplify/ConstProp/AArch64/aarch64-sve-convert-from-svbool.ll @@ -0,0 +1,10 @@ +; RUN: opt -instsimplify -S -o - < %s | FileCheck %s + +define <vscale x 2 x i1> @reinterpret_zero() { +; CHECK-LABEL: @reinterpret_zero( +; CHECK: ret <vscale x 2 x i1> zeroinitializer + %pg = tail call <vscale x 2 x i1> @llvm.aarch64.sve.convert.from.svbool.nxv2i1(<vscale x 16 x i1> zeroinitializer) + ret <vscale x 2 x i1> %pg +} + +declare <vscale x 2 x i1> @llvm.aarch64.sve.convert.from.svbool.nxv2i1(<vscale x 16 x i1>) diff --git a/llvm/test/Transforms/InstSimplify/ConstProp/AArch64/lit.local.cfg b/llvm/test/Transforms/InstSimplify/ConstProp/AArch64/lit.local.cfg new file mode 100644 index 000000000000..7184443994b6 --- /dev/null +++ b/llvm/test/Transforms/InstSimplify/ConstProp/AArch64/lit.local.cfg @@ -0,0 +1,2 @@ +if not 'AArch64' in config.root.targets: + config.unsupported = True |