[llvm] 8b8466f - [ArgumentPromotion] Bail if any callers are minsize
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Wed May 3 11:29:42 PDT 2023
Author: Arthur Eubanks
Date: 2023-05-03T11:29:15-07:00
New Revision: 8b8466fd31e5a194fd8ba7a73a0f23d32f164318
URL: https://github.com/llvm/llvm-project/commit/8b8466fd31e5a194fd8ba7a73a0f23d32f164318
DIFF: https://github.com/llvm/llvm-project/commit/8b8466fd31e5a194fd8ba7a73a0f23d32f164318.diff
LOG: [ArgumentPromotion] Bail if any callers are minsize
Argument promotion mostly works on functions with more than one caller (otherwise the function would be inlined or is dead), so there's a good chance that performing this increases code size since we introduce loads at every call site. If any caller is marked minsize, bail.
We could compare the number of loads/stores removed from the function with the number of loads introduced in callers, but that's TODO.
Reviewed By: nikic
Differential Revision: https://reviews.llvm.org/D149768
Added:
llvm/test/Transforms/ArgumentPromotion/minsize.ll
Modified:
llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
index 8c6c0728097ca..6d0cd21cbe92f 100644
--- a/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ b/llvm/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -764,6 +764,15 @@ static Function *promoteArguments(Function *F, FunctionAnalysisManager &FAM,
if (CB->isMustTailCall())
return nullptr;
+ // If the caller is marked minsize, this transformation may increase code
+ // size. We assume that there is more than one call to this function since
+ // otherwise this function would be inlined or is dead.
+ // TODO: compare the number of loads/stores removed from the function with
+ // the number of introduced loads in callees to see if this is profitable
+ // code-size-wise.
+ if (CB->getFunction()->hasMinSize())
+ return nullptr;
+
if (CB->getFunction() == F)
IsRecursive = true;
}
diff --git a/llvm/test/Transforms/ArgumentPromotion/minsize.ll b/llvm/test/Transforms/ArgumentPromotion/minsize.ll
new file mode 100644
index 0000000000000..7657c557d9e4a
--- /dev/null
+++ b/llvm/test/Transforms/ArgumentPromotion/minsize.ll
@@ -0,0 +1,63 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; RUN: opt -passes=argpromotion -S < %s | FileCheck %s
+
+define internal i32 @f1(ptr %p) {
+; CHECK-LABEL: define internal i32 @f1
+; CHECK-SAME: (i32 [[P_0_VAL:%.*]]) {
+; CHECK-NEXT: ret i32 [[P_0_VAL]]
+;
+ %i = load i32, ptr %p
+ ret i32 %i
+}
+
+define i32 @g1(ptr %p) {
+; CHECK-LABEL: define i32 @g1
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT: [[P_VAL:%.*]] = load i32, ptr [[P]], align 4
+; CHECK-NEXT: [[I:%.*]] = call i32 @f1(i32 [[P_VAL]])
+; CHECK-NEXT: ret i32 [[I]]
+;
+ %i = call i32 @f1(ptr %p)
+ ret i32 %i
+}
+
+define i32 @g2(ptr %p) {
+; CHECK-LABEL: define i32 @g2
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT: [[P_VAL:%.*]] = load i32, ptr [[P]], align 4
+; CHECK-NEXT: [[I:%.*]] = call i32 @f1(i32 [[P_VAL]])
+; CHECK-NEXT: ret i32 [[I]]
+;
+ %i = call i32 @f1(ptr %p)
+ ret i32 %i
+}
+
+define internal i32 @f2(ptr %p) {
+; CHECK-LABEL: define internal i32 @f2
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT: [[I:%.*]] = load i32, ptr [[P]], align 4
+; CHECK-NEXT: ret i32 [[I]]
+;
+ %i = load i32, ptr %p
+ ret i32 %i
+}
+
+define i32 @h1(ptr %p) minsize {
+; CHECK-LABEL: define i32 @h1
+; CHECK-SAME: (ptr [[P:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT: [[I:%.*]] = call i32 @f2(ptr [[P]])
+; CHECK-NEXT: ret i32 [[I]]
+;
+ %i = call i32 @f2(ptr %p)
+ ret i32 %i
+}
+
+define i32 @h2(ptr %p) {
+; CHECK-LABEL: define i32 @h2
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT: [[I:%.*]] = call i32 @f2(ptr [[P]])
+; CHECK-NEXT: ret i32 [[I]]
+;
+ %i = call i32 @f2(ptr %p)
+ ret i32 %i
+}
More information about the llvm-commits
mailing list