[llvm] r345072 - [HotColdSplitting] Attach MinSize to outlined code

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 23 12:41:12 PDT 2018


Author: vedantk
Date: Tue Oct 23 12:41:12 2018
New Revision: 345072

URL: http://llvm.org/viewvc/llvm-project?rev=345072&view=rev
Log:
[HotColdSplitting] Attach MinSize to outlined code

Outlined code is cold by assumption, so it makes sense to optimize it
for minimal code size rather than performance.

After r344869 moved the splitting pass to the end of the IR pipeline,
this does not result in much of a code size reduction. This is probably
because a comparatively small number backend transforms make use of the
MinSize hint.

Running LNT on x86_64, I see that 33/1020 binaries shrink for a total of
919 bytes of TEXT reduction. I didn't measure a significant performance
impact.

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

Added:
    llvm/trunk/test/Transforms/HotColdSplit/minsize.ll
Modified:
    llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp

Modified: llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp?rev=345072&r1=345071&r2=345072&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/HotColdSplitting.cpp Tue Oct 23 12:41:12 2018
@@ -360,6 +360,13 @@ HotColdSplitting::extractColdRegion(cons
       CS.setCallingConv(CallingConv::Cold);
     }
     CI->setIsNoInline();
+
+    // Try to make the outlined code as small as possible on the assumption
+    // that it's cold.
+    assert(!OutF->hasFnAttribute(Attribute::OptimizeNone) &&
+           "An outlined function should never be marked optnone");
+    OutF->addFnAttr(Attribute::MinSize);
+
     LLVM_DEBUG(llvm::dbgs() << "Outlined Region: " << *OutF);
     ORE.emit([&]() {
       return OptimizationRemark(DEBUG_TYPE, "HotColdSplit",

Added: llvm/trunk/test/Transforms/HotColdSplit/minsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/HotColdSplit/minsize.ll?rev=345072&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/HotColdSplit/minsize.ll (added)
+++ llvm/trunk/test/Transforms/HotColdSplit/minsize.ll Tue Oct 23 12:41:12 2018
@@ -0,0 +1,32 @@
+; RUN: opt -hotcoldsplit -S < %s | FileCheck %s
+
+; CHECK-LABEL: @fun
+; CHECK: codeRepl:
+; CHECK-NEXT: call void @fun_if.else
+
+define void @fun() {
+entry:
+  br i1 undef, label %if.then, label %if.else
+
+if.then:
+  ret void
+
+if.else:
+  br label %if.then4
+
+if.then4:
+  br i1 undef, label %if.then5, label %if.end
+
+if.then5:
+  br label %cleanup
+
+if.end:
+  br label %cleanup
+
+cleanup:
+  %cleanup.dest.slot.0 = phi i32 [ 1, %if.then5 ], [ 0, %if.end ]
+  unreachable
+}
+
+; CHECK: define {{.*}} @fun_if.else{{.*}}#[[outlined_func_attr:[0-9]+]]
+; CHECK: attributes #[[outlined_func_attr]] = { {{.*}}minsize




More information about the llvm-commits mailing list