[PATCH] D77058: [Clang] Add llvm.loop.unroll.disable to loops with -fno-unroll-loops.

Florian Hahn via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 30 07:33:17 PDT 2020


fhahn created this revision.
fhahn added reviewers: Meinersbur, hfinkel, dexonsmith, tejohnson.
Herald added a subscriber: zzheng.
Herald added a project: clang.

Currently Clang does not respect -fno-unroll-loops during LTO. During
D76916 <https://reviews.llvm.org/D76916> it was suggested to respect -fno-unroll-loops on a TU basis.

This patch uses the existing llvm.loop.unroll.disable metadata to
disable loop unrolling explicitly for each loop in the TU if
unrolling is disabled. This should ensure that loops from TUs compiled
with -fno-unroll-loops are skipped by the unroller during LTO.

This also means that if a loop from a TU with -fno-unroll-loops
gets inlined into a TU without this option, the loop won't be
unrolled.

Due to the fact that some transforms might drop loop metadata, there
potentially are cases in which we still unroll loops from TUs with
-fno-unroll-loops. I think we should fix those issues rather than
introducing a function attribute to disable loop unrolling during LTO.
Improving the metadata handling will benefit other use cases, like
various loop pragmas, too. And it is an improvement to clang completely
ignoring -fno-unroll-loops during LTO.

If that direction looks good, we can use a similar approach to also
respect -fno-vectorize during LTO, at least for LoopVectorize.

In the future, this might also allow us to remove the UnrollLoops option
LLVM's PassManagerBuilder.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D77058

Files:
  clang/lib/CodeGen/CGLoopInfo.cpp
  clang/lib/CodeGen/CGLoopInfo.h
  clang/lib/CodeGen/CGStmt.cpp
  clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp
  clang/test/CodeGenCXX/pragma-unroll.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77058.253589.patch
Type: text/x-patch
Size: 6815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200330/44b9ed60/attachment-0001.bin>


More information about the cfe-commits mailing list