[llvm] [profcheck][CVP] Adding 'unknown' branch weights for `urem` expansion in CVP (PR #180637)
Jin Huang via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 16 21:37:35 PST 2026
https://github.com/jinhuang1102 updated https://github.com/llvm/llvm-project/pull/180637
>From 9463d2fac5dfb18d851c991aa9774f324ce8f8af Mon Sep 17 00:00:00 2001
From: Jin Huang <jingold at google.com>
Date: Mon, 9 Feb 2026 23:02:10 +0000
Subject: [PATCH] [profcheck] Adding 'unkonwn' branch weights for expanding
urem in CVP
---
.../Scalar/CorrelatedValuePropagation.cpp | 4 ++++
.../Transforms/CorrelatedValuePropagation/urem.ll | 14 +++++++++++---
llvm/utils/profcheck-xfail.txt | 3 ---
3 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
index 4f8eba4b2d12b..35952a7a1667a 100644
--- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
+++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp
@@ -32,9 +32,11 @@
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
+#include "llvm/IR/MDBuilder.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/PatternMatch.h"
+#include "llvm/IR/ProfDataUtils.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
@@ -878,6 +880,8 @@ static bool expandUDivOrURem(BinaryOperator *Instr, const ConstantRange &XCR,
auto *Cmp = B.CreateICmp(ICmpInst::ICMP_ULT, FrozenX, FrozenY,
Instr->getName() + ".cmp");
ExpandedOp = B.CreateSelect(Cmp, FrozenX, AdjX);
+ setExplicitlyUnknownBranchWeightsIfProfiled(
+ *cast<Instruction>(ExpandedOp), DEBUG_TYPE, Instr->getFunction());
} else {
auto *Cmp =
B.CreateICmp(ICmpInst::ICMP_UGE, X, Y, Instr->getName() + ".cmp");
diff --git a/llvm/test/Transforms/CorrelatedValuePropagation/urem.ll b/llvm/test/Transforms/CorrelatedValuePropagation/urem.ll
index e69deaa73d73b..0073a714a199a 100644
--- a/llvm/test/Transforms/CorrelatedValuePropagation/urem.ll
+++ b/llvm/test/Transforms/CorrelatedValuePropagation/urem.ll
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
; RUN: opt < %s -passes=correlated-propagation -S | FileCheck %s
define void @test_nop(i32 %n) {
@@ -114,13 +114,13 @@ exit:
ret void
}
-define void @test5(i32 %n) {
+define void @test5(i32 %n) !prof !0 {
; CHECK-LABEL: @test5(
; CHECK-NEXT: [[TRUNC:%.*]] = and i32 [[N:%.*]], 63
; CHECK-NEXT: [[TRUNC_FROZEN:%.*]] = freeze i32 [[TRUNC]]
; CHECK-NEXT: [[DIV_UREM:%.*]] = sub nuw i32 [[TRUNC_FROZEN]], 42
; CHECK-NEXT: [[DIV_CMP:%.*]] = icmp ult i32 [[TRUNC_FROZEN]], 42
-; CHECK-NEXT: [[DIV:%.*]] = select i1 [[DIV_CMP]], i32 [[TRUNC_FROZEN]], i32 [[DIV_UREM]]
+; CHECK-NEXT: [[DIV:%.*]] = select i1 [[DIV_CMP]], i32 [[TRUNC_FROZEN]], i32 [[DIV_UREM]], !prof [[PROF1:![0-9]+]]
; CHECK-NEXT: ret void
;
%trunc = and i32 %n, 63
@@ -472,3 +472,11 @@ define i1 @urem_i1() {
}
declare void @use(i1)
+
+!0 = !{!"function_entry_count", i64 1000}
+;.
+; CHECK: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) }
+;.
+; CHECK: [[META0:![0-9]+]] = !{!"function_entry_count", i64 1000}
+; CHECK: [[PROF1]] = !{!"unknown", !"correlated-value-propagation"}
+;.
diff --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt
index 454f3d8f8fe00..59e9abdf1415c 100644
--- a/llvm/utils/profcheck-xfail.txt
+++ b/llvm/utils/profcheck-xfail.txt
@@ -60,9 +60,6 @@ Transforms/Coroutines/coro-split-tbaa-md-neg.ll
Transforms/Coroutines/coro-split-tbaa-md.ll
Transforms/Coroutines/coro-split-noinline.ll
Transforms/Coroutines/no-suspend.ll
-Transforms/CorrelatedValuePropagation/cond-at-use.ll
-Transforms/CorrelatedValuePropagation/urem-expansion.ll
-Transforms/CorrelatedValuePropagation/urem.ll
Transforms/CrossDSOCFI/basic.ll
Transforms/CrossDSOCFI/cfi_functions.ll
Transforms/CrossDSOCFI/thumb.ll
More information about the llvm-commits
mailing list