llvm.org GIT mirror llvm / 5ad8e3e
Add llvm.licm.disable metadata For some targets the LICM pass can result in sub-optimal code in some cases where it would be better not to run the pass, but it isn't always possible to suppress the transformations heuristically. Where the front-end has insight into such cases it is beneficial to attach loop metadata to disable the pass - this change adds the llvm.licm.disable metadata to enable that. Differential Revision: https://reviews.llvm.org/D64557 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368296 91177308-0d34-0410-b5e6-96231b3b80d8 Tim Corringham a month ago
5 changed file(s) with 63 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
53805380 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53815381
53825382 This metadata disables all optional loop transformations unless
5383 explicitly instructed using other transformation metdata such as
5383 explicitly instructed using other transformation metadata such as
53845384 ``llvm.loop.unroll.enable``. That is, no heuristic will try to determine
53855385 whether a transformation is profitable. The purpose is to avoid that the
53865386 loop is transformed to a different loop before an explicitly requested
57195719 '``llvm.loop.distribute.followup_all``' Metadata
57205720 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
57215721
5722 Thes attributes in this metdata is added to all followup loops of the
5722 The attributes in this metadata is added to all followup loops of the
57235723 loop distribution pass. See
57245724 :ref:`Transformation Metadata ` for details.
5725
5726 '``llvm.licm.disable``' Metadata
5727 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5728
5729 This metadata indicates that loop-invariant code motion (LICM) should not be
5730 performed on this loop. The metadata has a single operand which is the string
5731 ``llvm.licm.disable``. For example:
5732
5733 .. code-block:: llvm
5734
5735 !0 = !{!"llvm.licm.disable"}
5736
5737 Note that although it operates per loop it isn't given the llvm.loop prefix
5738 as it is not affected by the ``llvm.loop.disable_nonforced`` metadata.
57255739
57265740 '``llvm.access.group``' Metadata
57275741 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
214214 /// Look for the loop attribute that disables all transformation heuristic.
215215 bool hasDisableAllTransformsHint(const Loop *L);
216216
217 /// Look for the loop attribute that disables the LICM transformation heuristics.
218 bool hasDisableLICMTransformsHint(const Loop *L);
219
217220 /// The mode sets how eager a transformation should be applied.
218221 enum TransformationMode {
219222 /// The pass can use heuristics to determine whether a transformation should
328328 bool Changed = false;
329329
330330 assert(L->isLCSSAForm(*DT) && "Loop is not in LCSSA form.");
331
332 // If this loop has metadata indicating that LICM is not to be performed then
333 // just exit.
334 if (hasDisableLICMTransformsHint(L)) {
335 return false;
336 }
331337
332338 std::unique_ptr CurAST;
333339 std::unique_ptr MSSAU;
4444 #define DEBUG_TYPE "loop-utils"
4545
4646 static const char *LLVMLoopDisableNonforced = "llvm.loop.disable_nonforced";
47 static const char *LLVMLoopDisableLICM = "llvm.licm.disable";
4748
4849 bool llvm::formDedicatedExitBlocks(Loop *L, DominatorTree *DT, LoopInfo *LI,
4950 MemorySSAUpdater *MSSAU,
376377
377378 bool llvm::hasDisableAllTransformsHint(const Loop *L) {
378379 return getBooleanLoopAttribute(L, LLVMLoopDisableNonforced);
380 }
381
382 bool llvm::hasDisableLICMTransformsHint(const Loop *L) {
383 return getBooleanLoopAttribute(L, LLVMLoopDisableLICM);
379384 }
380385
381386 TransformationMode llvm::hasUnrollTransformation(Loop *L) {
0 ; RUN: opt < %s -S -basicaa -licm | FileCheck %s
1
2 ; Check that the LICM pass does not operate on a loop which has the
3 ; llvm.licm.disable metadata.
4 ; CHECK-LABEL: @licm_disable
5 ; CHECK: entry:
6 ; CHECK-NOT: load
7 ; CHECK: do.body:
8 ; CHECK: load i64, i64* bitcast (i32** @in to i64*)
9
10 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
11 target triple = "x86_64-pc-windows-msvc"
12
13 @in = internal unnamed_addr global i32* null, align 8
14 @out = internal unnamed_addr global i32* null, align 8
15
16 define void @licm_disable(i32 %N) {
17 entry:
18 br label %do.body
19
20 do.body: ; preds = %entry
21 %i.0 = phi i32 [ 0, %entry ], [ %inc, %do.body ]
22 %v1 = load i64, i64* bitcast (i32** @in to i64*), align 8
23 store i64 %v1, i64* bitcast (i32** @out to i64*), align 8
24 %inc = add nsw i32 %i.0, 1
25 %cmp = icmp slt i32 %inc, %N
26 br i1 %cmp, label %do.body, label %do.end, !llvm.loop !1
27
28 do.end: ; preds = %do.body
29 ret void
30 }
31 !1 = !{!1, !2}
32 !2 = !{!"llvm.licm.disable"}