diff options
author | Simon Moll <simon.moll@emea.nec.com> | 2022-03-16 11:10:11 +0100 |
---|---|---|
committer | Simon Moll <simon.moll@emea.nec.com> | 2022-03-16 11:10:32 +0100 |
commit | 0aab344104034e6191114a74f0d9eb5129bf550d (patch) | |
tree | 6defd8f22bff76c318bc13a23cff79dcd365fef3 /clang/lib/CodeGen/CodeGenFunction.cpp | |
parent | 9e24f0f4589dfdbc405f72eddd174af7511b2ff3 (diff) | |
download | llvm-0aab344104034e6191114a74f0d9eb5129bf550d.zip llvm-0aab344104034e6191114a74f0d9eb5129bf550d.tar.gz llvm-0aab344104034e6191114a74f0d9eb5129bf550d.tar.bz2 |
[Clang] Allow "ext_vector_type" applied to Booleans
This is the `ext_vector_type` alternative to D81083.
This patch extends Clang to allow 'bool' as a valid vector element type
(attribute ext_vector_type) in C/C++.
This is intended as the canonical type for SIMD masks and facilitates
clean vector intrinsic declarations. Vectors of i1 are supported on IR
level and below down to many SIMD ISAs, such as AVX512, ARM SVE (fixed
vector length) and the VE target (NEC SX-Aurora TSUBASA).
The RFC on cfe-dev: https://lists.llvm.org/pipermail/cfe-dev/2020-May/065434.html
Reviewed By: erichkeane
Differential Revision: https://reviews.llvm.org/D88905
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index c1f3a30..e652abb 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -2765,3 +2765,19 @@ CodeGenFunction::emitCondLikelihoodViaExpectIntrinsic(llvm::Value *Cond, } llvm_unreachable("Unknown Likelihood"); } + +llvm::Value *CodeGenFunction::emitBoolVecConversion(llvm::Value *SrcVec, + unsigned NumElementsDst, + const llvm::Twine &Name) { + auto *SrcTy = cast<llvm::FixedVectorType>(SrcVec->getType()); + unsigned NumElementsSrc = SrcTy->getNumElements(); + if (NumElementsSrc == NumElementsDst) + return SrcVec; + + std::vector<int> ShuffleMask(NumElementsDst, -1); + for (unsigned MaskIdx = 0; + MaskIdx < std::min<>(NumElementsDst, NumElementsSrc); ++MaskIdx) + ShuffleMask[MaskIdx] = MaskIdx; + + return Builder.CreateShuffleVector(SrcVec, ShuffleMask, Name); +} |