[PATCH] D104365: [FuncSpec] Enabling specializing direct constant
Chuanqi Xu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 28 05:22:14 PDT 2021
ChuanqiXu updated this revision to Diff 354850.
ChuanqiXu added a comment.
Add an option to control the behavior.
Then I did some statistics for SPEC2017int
The total number of specialized functions increased about 18% (from 49 to 58)
Then I didn't find significant compile-time change with turning option on.
I wonder if this means that we can turn this option on by default.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D104365/new/
https://reviews.llvm.org/D104365
Files:
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-integers.ll
Index: llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-integers.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-integers.ll
@@ -0,0 +1,44 @@
+; RUN: opt -function-specialization -function-specialization-for-literal-constant=true -S < %s | FileCheck %s
+
+; Check that the direct constant parameter could be specialized.
+; CHECK: @foo.1(
+; CHECK: @foo.2(
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+
+declare i32 @getValue()
+declare i1 @getCond()
+
+define internal i32 @foo(i1 %break_cond) {
+entry:
+ br label %loop.entry
+
+loop.entry:
+ br label %loop2.entry
+
+loop2.entry:
+ br label %loop2.body
+
+loop2.body:
+ %value = call i32 @getValue()
+ br i1 %break_cond, label %loop2.end, label %return
+
+loop2.end:
+ %cond.end = call i1 @getCond()
+ br i1 %cond.end, label %loop2.entry, label %loop.end
+
+loop.end:
+ %cond2.end = call i1 @getCond()
+ br i1 %cond2.end, label %loop.entry, label %return
+
+return:
+ ret i32 %value
+}
+
+define dso_local i32 @bar(i32 %x, i32 %y) {
+entry:
+ %retval.1 = call i32 @foo(i1 1)
+ %retval.2 = call i32 @foo(i1 0)
+ %retval = add nsw i32 %retval.1, %retval.2
+ ret i32 %retval
+}
\ No newline at end of file
Index: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -64,6 +64,10 @@
cl::desc("Average loop iteration count cost"),
cl::init(10));
+static cl::opt<bool> EnableSpecializeForLiteralConstant(
+ "function-specialization-for-literal-constant", cl::init(false), cl::Hidden,
+ cl::desc("Make function specialization available for literal constant."));
+
// Helper to check if \p LV is either overdefined or a constant int.
static bool isOverdefined(const ValueLatticeElement &LV) {
return !LV.isUnknownOrUndef() && !LV.isConstant();
@@ -471,17 +475,11 @@
}
}
- // Get the lattice value for the value the call site passes to the
- // argument. If this value is not constant, move on to the next call
- // site. Additionally, set the AllConstant flag to false.
- if (V != A && !Solver.getLatticeValueFor(V).isConstant()) {
+ if (isa<Constant>(V) && (Solver.getLatticeValueFor(V).isConstant() ||
+ EnableSpecializeForLiteralConstant))
+ Constants.push_back(cast<Constant>(V));
+ else
AllConstant = false;
- continue;
- }
-
- // Add the constant to the set.
- if (auto *C = dyn_cast<Constant>(CS.getArgOperand(A->getArgNo())))
- Constants.push_back(C);
}
// If the argument can only take on constant values, AllConstant will be
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104365.354850.patch
Type: text/x-patch
Size: 2951 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210628/8e526847/attachment-0001.bin>
More information about the llvm-commits
mailing list