[llvm] [FuncSpec] Enable SpecializeLiteralConstant by default (PR #113442)
Alexandros Lamprineas via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 24 16:44:05 PDT 2024
================
@@ -0,0 +1,147 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --include-generated-funcs --version 5
+; RUN: opt -passes="ipsccp<func-spec>" -force-specialization \
+; RUN: -funcspec-max-iters=3 -S < %s | FileCheck %s
+
+; RUN: opt -passes="ipsccp<func-spec>" -force-specialization \
+; RUN: -funcspec-for-literal-constant=false -funcspec-max-iters=3 \
+; RUN: -S < %s | FileCheck %s --check-prefix=NOLIT
+
+ at global_true = constant i1 true
+ at global_false = constant i1 false
+
+define i64 @main() {
+entry:
+ %binop1 = call ptr @select_binop(ptr @global_true)
+ %binop2 = call ptr @select_binop(ptr @global_false)
+
+ %c1 = call i64 @compute(ptr %binop1)
+ %c2 = call i64 @compute(ptr %binop2)
+ %add = add i64 %c1, %c2
+ ret i64 %add
+}
+
+define ptr @select_binop(ptr %flag) {
+ %flag.val = load i1, ptr %flag
+ %binop = select i1 %flag.val, ptr @plus, ptr @minus
+ ret ptr %binop
+}
+
+define internal i64 @compute(ptr %binop) {
+entry:
+ %res = call i64 %binop(i64 1, i64 1)
+ ret i64 %res
+}
+
+define internal i64 @plus(i64 %x) {
+entry:
+ %sum = add i64 %x, 1
+ ret i64 %sum
+}
+
+define internal i64 @minus(i64 %x) {
+entry:
+ %diff = sub i64 %x, 1
+ ret i64 %diff
+}
+; CHECK-LABEL: define i64 @main() {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[BINOP1:%.*]] = call ptr @select_binop.specialized.1(ptr @global_true)
+; CHECK-NEXT: [[BINOP2:%.*]] = call ptr @select_binop.specialized.2(ptr @global_false)
+; CHECK-NEXT: [[C1:%.*]] = call i64 @compute.specialized.3(ptr @plus)
+; CHECK-NEXT: [[C2:%.*]] = call i64 @compute.specialized.4(ptr @minus)
+; CHECK-NEXT: [[ADD:%.*]] = add i64 [[C1]], [[C2]]
----------------
labrinea wrote:
>From a quick debug I noticed that plus and minus are not considered for specialization because they have not yet replaced the binop in the body of compute.specialized.3 and compute.specialized.4 (the Solver only knowns their lattice value), therefore findSpecializations does not find these callsites in the users list.
https://github.com/llvm/llvm-project/pull/113442
More information about the llvm-commits
mailing list