[all-commits] [llvm/llvm-project] 338be9: [Clang] Add llvm.loop.unroll.disable to loops with...

Florian Hahn via All-commits all-commits at lists.llvm.org
Tue Apr 7 06:02:19 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 338be9c59527c3d172f64e8861bcbb472297d52d
      https://github.com/llvm/llvm-project/commit/338be9c59527c3d172f64e8861bcbb472297d52d
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2020-04-07 (Tue, 07 Apr 2020)

  Changed paths:
    M clang/lib/CodeGen/CGLoopInfo.cpp
    M clang/lib/CodeGen/CGLoopInfo.h
    M clang/lib/CodeGen/CGStmt.cpp
    A clang/test/CodeGenCXX/fno-unroll-loops-metadata.cpp
    M clang/test/CodeGenCXX/pragma-unroll.cpp

  Log Message:
  -----------
  [Clang] Add llvm.loop.unroll.disable to loops with -fno-unroll-loops.

Currently Clang does not respect -fno-unroll-loops during LTO. During
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.

Reviewers: Meinersbur, hfinkel, dexonsmith, tejohnson

Reviewed By: Meinersbur, tejohnson

Differential Revision: https://reviews.llvm.org/D77058




More information about the All-commits mailing list