Skip to content

[NFC][ubsan] Add mixed filter test case #100679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

vitalybuka
Copy link
Collaborator

Currently "random" overrides "hotness",
we need to make them work together.

Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented Jul 26, 2024

@llvm/pr-subscribers-llvm-transforms

Author: Vitaly Buka (vitalybuka)

Changes

Currently "random" overrides "hotness",
we need to make them work together.


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

1 Files Affected:

  • (modified) llvm/test/Transforms/lower-builtin-allow-check.ll (+166)
diff --git a/llvm/test/Transforms/lower-builtin-allow-check.ll b/llvm/test/Transforms/lower-builtin-allow-check.ll
index d992f420ac170..2f6fa96ffd9c5 100644
--- a/llvm/test/Transforms/lower-builtin-allow-check.ll
+++ b/llvm/test/Transforms/lower-builtin-allow-check.ll
@@ -4,6 +4,8 @@
 ; RUN: opt < %s -passes='function(lower-allow-check)' -lower-allow-check-random-rate=1 -S | FileCheck %s --check-prefixes=ALL
 ; RUN: opt < %s -passes='require<profile-summary>,function(lower-allow-check)' -lower-allow-check-percentile-cutoff-hot=990000 -S | FileCheck %s --check-prefixes=HOT99
 ; RUN: opt < %s -passes='require<profile-summary>,function(lower-allow-check)' -lower-allow-check-percentile-cutoff-hot=700000 -S | FileCheck %s --check-prefixes=HOT70
+; RUN: opt < %s -passes='require<profile-summary>,function(lower-allow-check)' -lower-allow-check-random-rate=0 -lower-allow-check-percentile-cutoff-hot=990000 -S | FileCheck %s --check-prefixes=NONE99
+; RUN: opt < %s -passes='require<profile-summary>,function(lower-allow-check)' -lower-allow-check-random-rate=1 -lower-allow-check-percentile-cutoff-hot=700000 -S | FileCheck %s --check-prefixes=ALL70
 
 target triple = "x86_64-pc-linux-gnu"
 
@@ -75,6 +77,32 @@ define dso_local noundef i32 @simple(ptr noundef readonly %0) {
 ; HOT70:       4:
 ; HOT70-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP0]], align 4
 ; HOT70-NEXT:    ret i32 [[TMP5]]
+;
+; NONE99-LABEL: define dso_local noundef i32 @simple(
+; NONE99-SAME: ptr noundef readonly [[TMP0:%.*]]) {
+; NONE99-NEXT:    [[CHK:%.*]] = icmp eq ptr [[TMP0]], null
+; NONE99-NEXT:    [[HOT:%.*]] = xor i1 false, true
+; NONE99-NEXT:    [[TMP2:%.*]] = or i1 [[CHK]], [[HOT]]
+; NONE99-NEXT:    br i1 [[TMP2]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; NONE99:       3:
+; NONE99-NEXT:    tail call void @llvm.ubsantrap(i8 22)
+; NONE99-NEXT:    unreachable
+; NONE99:       4:
+; NONE99-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP0]], align 4
+; NONE99-NEXT:    ret i32 [[TMP5]]
+;
+; ALL70-LABEL: define dso_local noundef i32 @simple(
+; ALL70-SAME: ptr noundef readonly [[TMP0:%.*]]) {
+; ALL70-NEXT:    [[CHK:%.*]] = icmp eq ptr [[TMP0]], null
+; ALL70-NEXT:    [[HOT:%.*]] = xor i1 true, true
+; ALL70-NEXT:    [[TMP2:%.*]] = or i1 [[CHK]], [[HOT]]
+; ALL70-NEXT:    br i1 [[TMP2]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; ALL70:       3:
+; ALL70-NEXT:    tail call void @llvm.ubsantrap(i8 22)
+; ALL70-NEXT:    unreachable
+; ALL70:       4:
+; ALL70-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP0]], align 4
+; ALL70-NEXT:    ret i32 [[TMP5]]
 ;
   %chk = icmp eq ptr %0, null
   %allow = call i1 @llvm.allow.ubsan.check(i8 22)
@@ -157,6 +185,32 @@ define dso_local noundef i32 @hot(ptr noundef readonly %0) !prof !36 {
 ; HOT70:       4:
 ; HOT70-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP0]], align 4
 ; HOT70-NEXT:    ret i32 [[TMP5]]
+;
+; NONE99-LABEL: define dso_local noundef i32 @hot(
+; NONE99-SAME: ptr noundef readonly [[TMP0:%.*]]) !prof [[PROF16:![0-9]+]] {
+; NONE99-NEXT:    [[CHK:%.*]] = icmp eq ptr [[TMP0]], null
+; NONE99-NEXT:    [[HOT:%.*]] = xor i1 false, true
+; NONE99-NEXT:    [[TMP2:%.*]] = or i1 [[CHK]], [[HOT]]
+; NONE99-NEXT:    br i1 [[TMP2]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; NONE99:       3:
+; NONE99-NEXT:    tail call void @llvm.ubsantrap(i8 22)
+; NONE99-NEXT:    unreachable
+; NONE99:       4:
+; NONE99-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP0]], align 4
+; NONE99-NEXT:    ret i32 [[TMP5]]
+;
+; ALL70-LABEL: define dso_local noundef i32 @hot(
+; ALL70-SAME: ptr noundef readonly [[TMP0:%.*]]) !prof [[PROF16:![0-9]+]] {
+; ALL70-NEXT:    [[CHK:%.*]] = icmp eq ptr [[TMP0]], null
+; ALL70-NEXT:    [[HOT:%.*]] = xor i1 true, true
+; ALL70-NEXT:    [[TMP2:%.*]] = or i1 [[CHK]], [[HOT]]
+; ALL70-NEXT:    br i1 [[TMP2]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; ALL70:       3:
+; ALL70-NEXT:    tail call void @llvm.ubsantrap(i8 22)
+; ALL70-NEXT:    unreachable
+; ALL70:       4:
+; ALL70-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP0]], align 4
+; ALL70-NEXT:    ret i32 [[TMP5]]
 ;
   %chk = icmp eq ptr %0, null
   %allow = call i1 @llvm.allow.ubsan.check(i8 22)
@@ -238,6 +292,32 @@ define dso_local noundef i32 @veryHot(ptr noundef readonly %0) !prof !39 {
 ; HOT70:       4:
 ; HOT70-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP0]], align 4
 ; HOT70-NEXT:    ret i32 [[TMP5]]
+;
+; NONE99-LABEL: define dso_local noundef i32 @veryHot(
+; NONE99-SAME: ptr noundef readonly [[TMP0:%.*]]) !prof [[PROF17:![0-9]+]] {
+; NONE99-NEXT:    [[CHK:%.*]] = icmp eq ptr [[TMP0]], null
+; NONE99-NEXT:    [[HOT:%.*]] = xor i1 false, true
+; NONE99-NEXT:    [[TMP2:%.*]] = or i1 [[CHK]], [[HOT]]
+; NONE99-NEXT:    br i1 [[TMP2]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; NONE99:       3:
+; NONE99-NEXT:    tail call void @llvm.ubsantrap(i8 22)
+; NONE99-NEXT:    unreachable
+; NONE99:       4:
+; NONE99-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP0]], align 4
+; NONE99-NEXT:    ret i32 [[TMP5]]
+;
+; ALL70-LABEL: define dso_local noundef i32 @veryHot(
+; ALL70-SAME: ptr noundef readonly [[TMP0:%.*]]) !prof [[PROF17:![0-9]+]] {
+; ALL70-NEXT:    [[CHK:%.*]] = icmp eq ptr [[TMP0]], null
+; ALL70-NEXT:    [[HOT:%.*]] = xor i1 true, true
+; ALL70-NEXT:    [[TMP2:%.*]] = or i1 [[CHK]], [[HOT]]
+; ALL70-NEXT:    br i1 [[TMP2]], label [[TMP3:%.*]], label [[TMP4:%.*]]
+; ALL70:       3:
+; ALL70-NEXT:    tail call void @llvm.ubsantrap(i8 22)
+; ALL70-NEXT:    unreachable
+; ALL70:       4:
+; ALL70-NEXT:    [[TMP5:%.*]] = load i32, ptr [[TMP0]], align 4
+; ALL70-NEXT:    ret i32 [[TMP5]]
 ;
   %chk = icmp eq ptr %0, null
   %allow = call i1 @llvm.allow.ubsan.check(i8 22)
@@ -350,6 +430,44 @@ define dso_local noundef i32 @branchColdFnHot(i32 noundef %0, ptr noundef readon
 ; HOT70:       9:
 ; HOT70-NEXT:    [[TMP10:%.*]] = phi i32 [ [[TMP8]], [[TMP7]] ], [ 0, [[TMP2:%.*]] ]
 ; HOT70-NEXT:    ret i32 [[TMP10]]
+;
+; NONE99-LABEL: define dso_local noundef i32 @branchColdFnHot(
+; NONE99-SAME: i32 noundef [[TMP0:%.*]], ptr noundef readonly [[TMP1:%.*]]) !prof [[PROF17]] {
+; NONE99-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[TMP0]], 0
+; NONE99-NEXT:    br i1 [[TMP3]], label [[TMP9:%.*]], label [[TMP4:%.*]], !prof [[PROF18:![0-9]+]]
+; NONE99:       4:
+; NONE99-NEXT:    [[CHK:%.*]] = icmp eq ptr [[TMP1]], null
+; NONE99-NEXT:    [[HOT:%.*]] = xor i1 false, true
+; NONE99-NEXT:    [[TMP5:%.*]] = or i1 [[CHK]], [[HOT]]
+; NONE99-NEXT:    br i1 [[TMP5]], label [[TMP6:%.*]], label [[TMP7:%.*]]
+; NONE99:       6:
+; NONE99-NEXT:    tail call void @llvm.ubsantrap(i8 22)
+; NONE99-NEXT:    unreachable
+; NONE99:       7:
+; NONE99-NEXT:    [[TMP8:%.*]] = load i32, ptr [[TMP1]], align 4
+; NONE99-NEXT:    br label [[TMP9]]
+; NONE99:       9:
+; NONE99-NEXT:    [[TMP10:%.*]] = phi i32 [ [[TMP8]], [[TMP7]] ], [ 0, [[TMP2:%.*]] ]
+; NONE99-NEXT:    ret i32 [[TMP10]]
+;
+; ALL70-LABEL: define dso_local noundef i32 @branchColdFnHot(
+; ALL70-SAME: i32 noundef [[TMP0:%.*]], ptr noundef readonly [[TMP1:%.*]]) !prof [[PROF17]] {
+; ALL70-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[TMP0]], 0
+; ALL70-NEXT:    br i1 [[TMP3]], label [[TMP9:%.*]], label [[TMP4:%.*]], !prof [[PROF18:![0-9]+]]
+; ALL70:       4:
+; ALL70-NEXT:    [[CHK:%.*]] = icmp eq ptr [[TMP1]], null
+; ALL70-NEXT:    [[HOT:%.*]] = xor i1 true, true
+; ALL70-NEXT:    [[TMP5:%.*]] = or i1 [[CHK]], [[HOT]]
+; ALL70-NEXT:    br i1 [[TMP5]], label [[TMP6:%.*]], label [[TMP7:%.*]]
+; ALL70:       6:
+; ALL70-NEXT:    tail call void @llvm.ubsantrap(i8 22)
+; ALL70-NEXT:    unreachable
+; ALL70:       7:
+; ALL70-NEXT:    [[TMP8:%.*]] = load i32, ptr [[TMP1]], align 4
+; ALL70-NEXT:    br label [[TMP9]]
+; ALL70:       9:
+; ALL70-NEXT:    [[TMP10:%.*]] = phi i32 [ [[TMP8]], [[TMP7]] ], [ 0, [[TMP2:%.*]] ]
+; ALL70-NEXT:    ret i32 [[TMP10]]
 ;
   %3 = icmp eq i32 %0, 0
   br i1 %3, label %9, label %4, !prof !38
@@ -469,6 +587,44 @@ define dso_local noundef i32 @branchHotFnCold(i32 noundef %0, ptr noundef readon
 ; HOT70:       9:
 ; HOT70-NEXT:    [[TMP10:%.*]] = phi i32 [ [[TMP8]], [[TMP7]] ], [ 0, [[TMP2:%.*]] ]
 ; HOT70-NEXT:    ret i32 [[TMP10]]
+;
+; NONE99-LABEL: define dso_local noundef i32 @branchHotFnCold(
+; NONE99-SAME: i32 noundef [[TMP0:%.*]], ptr noundef readonly [[TMP1:%.*]]) !prof [[PROF16]] {
+; NONE99-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[TMP0]], 0
+; NONE99-NEXT:    br i1 [[TMP3]], label [[TMP9:%.*]], label [[TMP4:%.*]], !prof [[PROF19:![0-9]+]]
+; NONE99:       4:
+; NONE99-NEXT:    [[CHK:%.*]] = icmp eq ptr [[TMP1]], null
+; NONE99-NEXT:    [[HOT:%.*]] = xor i1 false, true
+; NONE99-NEXT:    [[TMP5:%.*]] = or i1 [[CHK]], [[HOT]]
+; NONE99-NEXT:    br i1 [[TMP5]], label [[TMP6:%.*]], label [[TMP7:%.*]]
+; NONE99:       6:
+; NONE99-NEXT:    tail call void @llvm.ubsantrap(i8 22)
+; NONE99-NEXT:    unreachable
+; NONE99:       7:
+; NONE99-NEXT:    [[TMP8:%.*]] = load i32, ptr [[TMP1]], align 4
+; NONE99-NEXT:    br label [[TMP9]]
+; NONE99:       9:
+; NONE99-NEXT:    [[TMP10:%.*]] = phi i32 [ [[TMP8]], [[TMP7]] ], [ 0, [[TMP2:%.*]] ]
+; NONE99-NEXT:    ret i32 [[TMP10]]
+;
+; ALL70-LABEL: define dso_local noundef i32 @branchHotFnCold(
+; ALL70-SAME: i32 noundef [[TMP0:%.*]], ptr noundef readonly [[TMP1:%.*]]) !prof [[PROF16]] {
+; ALL70-NEXT:    [[TMP3:%.*]] = icmp eq i32 [[TMP0]], 0
+; ALL70-NEXT:    br i1 [[TMP3]], label [[TMP9:%.*]], label [[TMP4:%.*]], !prof [[PROF19:![0-9]+]]
+; ALL70:       4:
+; ALL70-NEXT:    [[CHK:%.*]] = icmp eq ptr [[TMP1]], null
+; ALL70-NEXT:    [[HOT:%.*]] = xor i1 true, true
+; ALL70-NEXT:    [[TMP5:%.*]] = or i1 [[CHK]], [[HOT]]
+; ALL70-NEXT:    br i1 [[TMP5]], label [[TMP6:%.*]], label [[TMP7:%.*]]
+; ALL70:       6:
+; ALL70-NEXT:    tail call void @llvm.ubsantrap(i8 22)
+; ALL70-NEXT:    unreachable
+; ALL70:       7:
+; ALL70-NEXT:    [[TMP8:%.*]] = load i32, ptr [[TMP1]], align 4
+; ALL70-NEXT:    br label [[TMP9]]
+; ALL70:       9:
+; ALL70-NEXT:    [[TMP10:%.*]] = phi i32 [ [[TMP8]], [[TMP7]] ], [ 0, [[TMP2:%.*]] ]
+; ALL70-NEXT:    ret i32 [[TMP10]]
 ;
   %3 = icmp eq i32 %0, 0
   br i1 %3, label %9, label %4, !prof !37
@@ -543,3 +699,13 @@ define dso_local noundef i32 @branchHotFnCold(i32 noundef %0, ptr noundef readon
 ; HOT70: [[PROF18]] = !{!"branch_weights", i32 1000, i32 1}
 ; HOT70: [[PROF19]] = !{!"branch_weights", i32 1, i32 1000}
 ;.
+; NONE99: [[PROF16]] = !{!"function_entry_count", i64 1000}
+; NONE99: [[PROF17]] = !{!"function_entry_count", i64 7000}
+; NONE99: [[PROF18]] = !{!"branch_weights", i32 1000, i32 1}
+; NONE99: [[PROF19]] = !{!"branch_weights", i32 1, i32 1000}
+;.
+; ALL70: [[PROF16]] = !{!"function_entry_count", i64 1000}
+; ALL70: [[PROF17]] = !{!"function_entry_count", i64 7000}
+; ALL70: [[PROF18]] = !{!"branch_weights", i32 1000, i32 1}
+; ALL70: [[PROF19]] = !{!"branch_weights", i32 1, i32 1000}
+;.

Created using spr 1.3.4

[skip ci]
Created using spr 1.3.4
@vitalybuka vitalybuka changed the base branch from users/vitalybuka/spr/main.nfcubsan-add-mixed-filter-test-case to main July 26, 2024 16:47
@vitalybuka vitalybuka merged commit 4826079 into main Jul 26, 2024
5 of 7 checks passed
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/nfcubsan-add-mixed-filter-test-case branch July 26, 2024 16:48
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.

3 participants