Tom Sun via llvm-dev
2018-Jan-19 08:38 UTC
[llvm-dev] Does OpenMP hints bypass the vectorisation legality check in llvm
Hi all, I am currently looking into how "#pragma omp for simd" is actually recognized in llvm. To my knowledge, clang will parse it and set metadata in IR to indicate this force-vectorization hint and later optimization passes would read it and vectorize the marked loop. Therefore, the loop should be vectorized even the compiler think it might not be safe to do so? So my assumption is that such force-vectorization hints should bypass both the vectorization legality and cost model check. However, in LoopVectorize.cpp, I can't see how this is done. All loops will be sent to a legality check of LVL.canVectorize() and, if this condition does not fit, it return to false directly without actually reaching the vectorization stage. Is there anything wrong with my assumption made on the use of force-vectorization hints? Thanks in advance, T -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180119/fa24bfb5/attachment.html>
Tian, Xinmin via llvm-dev
2018-Jan-19 17:54 UTC
[llvm-dev] Does OpenMP hints bypass the vectorisation legality check in llvm
Tom, your understanding is correct per OpenMP SIMD model. Our implementation behaves as you stated. Which is not part of LLVM main trunk yet. Xinmin From: llvm-dev [mailto:llvm-dev-bounces at lists.llvm.org] On Behalf Of Tom Sun via llvm-dev Sent: Friday, January 19, 2018 12:39 AM To: llvm-dev at lists.llvm.org Subject: [llvm-dev] Does OpenMP hints bypass the vectorisation legality check in llvm Hi all, I am currently looking into how "#pragma omp for simd" is actually recognized in llvm. To my knowledge, clang will parse it and set metadata in IR to indicate this force-vectorization hint and later optimization passes would read it and vectorize the marked loop. Therefore, the loop should be vectorized even the compiler think it might not be safe to do so? So my assumption is that such force-vectorization hints should bypass both the vectorization legality and cost model check. However, in LoopVectorize.cpp, I can't see how this is done. All loops will be sent to a legality check of LVL.canVectorize() and, if this condition does not fit, it return to false directly without actually reaching the vectorization stage. Is there anything wrong with my assumption made on the use of force-vectorization hints? Thanks in advance, T -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180119/94ac9dc6/attachment.html>
Hal Finkel via llvm-dev
2018-Jan-19 21:37 UTC
[llvm-dev] Does OpenMP hints bypass the vectorisation legality check in llvm
Hi, Tom, Yes, OpenMP SIMD hints are currently translated into metadata that is used by the vectorizer. If you'd like to know how that's done, see: http://llvm.org/docs/LangRef.html#llvm-mem-parallel-loop-access-metadata (and should also enable the vectorizer: http://llvm.org/docs/LangRef.html#llvm-loop-vectorize-enable-metadata) The relevant Clang code is in clang/lib/CodeGen/CGLoopInfo.cpp and lib/CodeGen/CGStmtOpenMP.cpp (see, in particular, the comments around emitSimdlenSafelenClause and EmitOMPSimdInit regarding safelen and semantics). The relevant check for the vectorizer is in LoopAccessAnalysis.cpp: const bool IsAnnotatedParallel = TheLoop->isAnnotatedParallel(); where isAnnotatedParallel checks for the parallel-loop-access metadata (that indicates that the loop is data parallel) and is part of LoopInfo. -Hal On 01/19/2018 02:38 AM, Tom Sun via llvm-dev wrote:> > Hi all, > > I am currently looking into how "#pragma omp for simd" is actually > recognized in llvm. To my knowledge, clang will parse it and set > metadata in IR to indicate this force-vectorization hint and later > optimization passes would read it and vectorize the marked loop. > Therefore, the loop should be vectorized even the compiler think it > might not be safe to do so? > > So my assumption is that such force-vectorization hints should bypass > both the vectorization legality and cost model check. However, in > LoopVectorize.cpp, I can't see how this is done. All loops will be > sent to a legality check of LVL.canVectorize() and, if this condition > does not fit, it return to false directly without actually reaching > the vectorization stage. > > Is there anything wrong with my assumption made on the use of > force-vectorization hints? > > Thanks in advance, > > T > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- Hal Finkel Lead, Compiler Technology and Programming Languages Leadership Computing Facility Argonne National Laboratory -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180119/750ff4fe/attachment-0001.html>
Maybe Matching Threads
- Does OpenMP hints bypass the vectorisation legality check in llvm
- : Does OpenMP hints bypass the vectorisation legality check in llvm
- [LLVMdev] Loop vectorizer behaviour for 2D arrays and parallel annotation
- [RFC] Compiled regression tests.
- [LLVMdev] First attempt at recognizing pointer reduction