Skip to content

Conversation

alanzhao1
Copy link
Contributor

This test is a follow up to 7d748a9 which fixes an assertion crash that occurs if the profile count is 0.

Additionally, modify profile-counts.ll to use update_test_checks.py.

This test is a follow up to llvm@7d748a9
which fixes an assertion crash that occurs if the profile count is 0.

Additionally, modify `profile-counts.ll` to use `update_test_checks.py`.
@llvmbot
Copy link
Member

llvmbot commented Sep 22, 2025

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-function-specialization

Author: Alan Zhao (alanzhao1)

Changes

This test is a follow up to 7d748a9 which fixes an assertion crash that occurs if the profile count is 0.

Additionally, modify profile-counts.ll to use update_test_checks.py.


Full diff: https://github.com/llvm/llvm-project/pull/160156.diff

1 Files Affected:

  • (modified) llvm/test/Transforms/FunctionSpecialization/profile-counts.ll (+77-20)
diff --git a/llvm/test/Transforms/FunctionSpecialization/profile-counts.ll b/llvm/test/Transforms/FunctionSpecialization/profile-counts.ll
index bdf7690a71b69..4d26247ad09cb 100644
--- a/llvm/test/Transforms/FunctionSpecialization/profile-counts.ll
+++ b/llvm/test/Transforms/FunctionSpecialization/profile-counts.ll
@@ -1,20 +1,40 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 6
 ; RUN: opt -passes="ipsccp<func-spec>" -force-specialization -S < %s | FileCheck %s
 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
 
 @A = external dso_local constant i32, align 4
 @B = external dso_local constant i32, align 4
 
-; CHECK: define dso_local i32 @bar(i32 %x, i32 %y, ptr %z) !prof ![[BAR_PROF:[0-9]]] {
+;.
+; CHECK: @A = external dso_local constant i32, align 4
+; CHECK: @B = external dso_local constant i32, align 4
+;.
 define dso_local i32 @bar(i32 %x, i32 %y, ptr %z) !prof !0 {
+; CHECK-LABEL: define dso_local i32 @bar(
+; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]], ptr [[Z:%.*]]) !prof [[PROF0:![0-9]+]] {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp ne i32 [[X]], 0
+; CHECK-NEXT:    br i1 [[TOBOOL]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]], !prof [[PROF1:![0-9]+]]
+; CHECK:       [[IF_THEN]]:
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @foo.specialized.1(i32 [[X]], ptr @A)
+; CHECK-NEXT:    [[CALL1:%.*]] = call i32 @foo.specialized.2(i32 [[Y]], ptr @B)
+; CHECK-NEXT:    [[CALL2:%.*]] = call i32 @foo.specialized.2(i32 [[Y]], ptr @B)
+; CHECK-NEXT:    [[ADD:%.*]] = add i32 [[CALL]], [[CALL1]]
+; CHECK-NEXT:    [[ADD1:%.*]] = add i32 [[ADD]], [[CALL2]]
+; CHECK-NEXT:    br label %[[RETURN:.*]]
+; CHECK:       [[IF_ELSE]]:
+; CHECK-NEXT:    [[CALL3:%.*]] = call i32 @foo.specialized.2(i32 [[Y]], ptr @B)
+; CHECK-NEXT:    br label %[[RETURN]]
+; CHECK:       [[RETURN]]:
+; CHECK-NEXT:    [[RETVAL_0:%.*]] = phi i32 [ [[ADD1]], %[[IF_THEN]] ], [ [[CALL3]], %[[IF_ELSE]] ]
+; CHECK-NEXT:    [[CALL4:%.*]] = call i32 @foo(i32 [[X]], ptr [[Z]])
+; CHECK-NEXT:    [[ADD2:%.*]] = add i32 [[RETVAL_0]], [[CALL4]]
+; CHECK-NEXT:    ret i32 [[ADD2]]
+;
 entry:
   %tobool = icmp ne i32 %x, 0
-; CHECK: br i1 %tobool, label %if.then, label %if.else, !prof ![[BRANCH_PROF:[0-9]]]
   br i1 %tobool, label %if.then, label %if.else, !prof !1
 
-; CHECK: if.then:
-; CHECK: call i32 @foo.specialized.1(i32 %x, ptr @A)
-; CHECK: call i32 @foo.specialized.2(i32 %y, ptr @B)
-; CHECK: call i32 @foo.specialized.2(i32 %y, ptr @B)
 if.then:
   %call = call i32 @foo(i32 %x, ptr @A)
   %call1 = call i32 @foo(i32 %y, ptr @B)
@@ -23,14 +43,10 @@ if.then:
   %add1 = add i32 %add, %call2
   br label %return
 
-; CHECK: if.else:
-; CHECK: call i32 @foo.specialized.2(i32 %y, ptr @B)
 if.else:
   %call3 = call i32 @foo(i32 %y, ptr @B)
   br label %return
 
-; CHECK: return:
-; CHECK: call i32 @foo(i32 %x, ptr %z)
 return:
   %retval.0 = phi i32 [ %add1, %if.then ], [ %call3, %if.else ]
   %call4 = call i32 @foo(i32 %x, ptr %z);
@@ -38,21 +54,62 @@ return:
   ret i32 %add2
 }
 
-; CHECK: define internal i32 @foo(i32 %x, ptr %b) !prof ![[FOO_UNSPEC_PROF:[0-9]]]
-; CHECK: define internal i32 @foo.specialized.1(i32 %x, ptr %b) !prof ![[FOO_SPEC_1_PROF:[0-9]]]
-; CHECK: define internal i32 @foo.specialized.2(i32 %x, ptr %b) !prof ![[FOO_SPEC_2_PROF:[0-9]]]
-define internal i32 @foo(i32 %x, ptr %b) !prof !2 {
+define dso_local i32 @baz(i32 %x, i32 %y) !prof !2 {
+; CHECK-LABEL: define dso_local i32 @baz(
+; CHECK-SAME: i32 [[X:%.*]], i32 [[Y:%.*]]) !prof [[PROF2:![0-9]+]] {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TOBOOL:%.*]] = icmp ne i32 [[X]], 0
+; CHECK-NEXT:    br i1 [[TOBOOL]], label %[[IF_THEN:.*]], label %[[IF_ELSE:.*]]
+; CHECK:       [[IF_THEN]]:
+; CHECK-NEXT:    [[CALL:%.*]] = call i32 @foo.specialized.1(i32 [[X]], ptr @A)
+; CHECK-NEXT:    br label %[[RETURN:.*]]
+; CHECK:       [[IF_ELSE]]:
+; CHECK-NEXT:    [[CALL1:%.*]] = call i32 @foo.specialized.2(i32 [[Y]], ptr @B)
+; CHECK-NEXT:    br label %[[RETURN]]
+; CHECK:       [[RETURN]]:
+; CHECK-NEXT:    [[RETVAL_0:%.*]] = phi i32 [ [[CALL]], %[[IF_THEN]] ], [ [[CALL1]], %[[IF_ELSE]] ]
+; CHECK-NEXT:    ret i32 [[RETVAL_0]]
+;
+entry:
+  %tobool = icmp ne i32 %x, 0
+  br i1 %tobool, label %if.then, label %if.else
+
+if.then:
+  %call = call i32 @foo(i32 %x, ptr @A)
+  br label %return
+
+if.else:
+  %call1 = call i32 @foo(i32 %y, ptr @B)
+  br label %return
+
+return:
+  %retval.0 = phi i32 [ %call, %if.then ], [ %call1, %if.else ]
+  ret i32 %retval.0
+}
+
+define internal i32 @foo(i32 %x, ptr %b) !prof !3 {
+; CHECK-LABEL: define internal i32 @foo(
+; CHECK-SAME: i32 [[X:%.*]], ptr [[B:%.*]]) !prof [[PROF3:![0-9]+]] {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP0:%.*]] = load i32, ptr [[B]], align 4
+; CHECK-NEXT:    [[ADD:%.*]] = add nsw i32 [[X]], [[TMP0]]
+; CHECK-NEXT:    ret i32 [[ADD]]
+;
 entry:
   %0 = load i32, ptr %b, align 4
   %add = add nsw i32 %x, %0
   ret i32 %add
 }
 
-; CHECK: ![[BAR_PROF]] = !{!"function_entry_count", i64 1000}
-; CHECK: ![[BRANCH_PROF]] = !{!"branch_weights", i32 1, i32 3}
-; CHECK: ![[FOO_UNSPEC_PROF]] =  !{!"function_entry_count", i64 500}
-; CHECK: ![[FOO_SPEC_1_PROF]] = !{!"function_entry_count", i64 250}
-; CHECK: ![[FOO_SPEC_2_PROF]] = !{!"function_entry_count", i64 1250}
 !0 = !{!"function_entry_count", i64 1000}
 !1 = !{!"branch_weights", i32 1, i32 3}
-!2 = !{!"function_entry_count", i64 2000}
+!2 = !{!"function_entry_count", i64 0}
+!3 = !{!"function_entry_count", i64 2000}
+;.
+; CHECK: [[PROF0]] = !{!"function_entry_count", i64 1000}
+; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 3}
+; CHECK: [[PROF2]] = !{!"function_entry_count", i64 0}
+; CHECK: [[PROF3]] = !{!"function_entry_count", i64 500}
+; CHECK: [[META4:![0-9]+]] = !{!"function_entry_count", i64 250}
+; CHECK: [[META5:![0-9]+]] = !{!"function_entry_count", i64 1250}
+;.

@alanzhao1 alanzhao1 merged commit 761c31e into llvm:main Sep 22, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants