[llvm] 3bbfa71 - [SCEVExpander] Mark selects with unknown profile. (#224362)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 22 02:28:13 PDT 2026
Author: Florian Hahn
Date: 2026-09-22T09:28:06Z
New Revision: 3bbfa7173bbfb0a231674822efb84a3e0b9f8c23
URL: https://github.com/llvm/llvm-project/commit/3bbfa7173bbfb0a231674822efb84a3e0b9f8c23
DIFF: https://github.com/llvm/llvm-project/commit/3bbfa7173bbfb0a231674822efb84a3e0b9f8c23.diff
LOG: [SCEVExpander] Mark selects with unknown profile. (#224362)
SCEVExpander creates selects when expanding min/max expressions for
pointers and predicates. In neither case there is any information on how
likely either arm of the select is. Annotate with unknown profile.
This is part of addressing the remaining profcheck failures in
LoopVectorize: https://github.com/llvm/llvm-project/issues/161235.
PR: https://github.com/llvm/llvm-project/pull/224362
Added:
Modified:
llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
llvm/test/Transforms/LoopVectorize/scev-check-unknown-prof.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
index 3fc65a441d8cc..3f698822449ed 100644
--- a/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
+++ b/llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
@@ -24,6 +24,7 @@
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/PatternMatch.h"
+#include "llvm/IR/ProfDataUtils.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/Local.h"
@@ -1580,7 +1581,8 @@ Value *SCEVExpander::expandMinMaxExpr(SCEVUseT<const SCEVNAryExpr *> S,
else {
Value *ICmp =
Builder.CreateICmp(MinMaxIntrinsic::getPredicate(IntrinID), LHS, RHS);
- Sel = Builder.CreateSelect(ICmp, LHS, RHS, Name);
+ Sel = Builder.CreateSelectWithUnknownProfile(ICmp, LHS, RHS,
+ "scev-expander", Name);
}
LHS = Sel;
}
@@ -2340,7 +2342,8 @@ Value *SCEVExpander::generateOverflowCheck(const SCEVAddRecExpr *AR,
Builder.SetInsertPoint(Loc);
// Compute |Step|
Value *StepCompare = Builder.CreateICmp(ICmpInst::ICMP_SLT, StepValue, Zero);
- Value *AbsStep = Builder.CreateSelect(StepCompare, NegStepValue, StepValue);
+ Value *AbsStep = Builder.CreateSelectWithUnknownProfile(
+ StepCompare, NegStepValue, StepValue, "scev-expander");
// Compute |Step| * Backedge
// Compute:
@@ -2399,7 +2402,8 @@ Value *SCEVExpander::generateOverflowCheck(const SCEVAddRecExpr *AR,
Signed ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT, Sub, StartValue);
if (NeedPosCheck && NeedNegCheck) {
// Select the answer based on the sign of Step.
- EndCheck = Builder.CreateSelect(StepCompare, EndCompareGT, EndCompareLT);
+ EndCheck = Builder.CreateSelectWithUnknownProfile(
+ StepCompare, EndCompareGT, EndCompareLT, "scev-expander");
}
return Builder.CreateOr(EndCheck, OfMul);
};
diff --git a/llvm/test/Transforms/LoopVectorize/scev-check-unknown-prof.ll b/llvm/test/Transforms/LoopVectorize/scev-check-unknown-prof.ll
index cb145d88c8b05..f2d2f13a39a6b 100644
--- a/llvm/test/Transforms/LoopVectorize/scev-check-unknown-prof.ll
+++ b/llvm/test/Transforms/LoopVectorize/scev-check-unknown-prof.ll
@@ -11,8 +11,8 @@ define void @wrap_check(i32 %n, i32 %step) !prof !0 {
; CHECK: [[LOOP_PREHEADER]]:
; CHECK: br i1 [[MIN_ITERS_CHECK:%.*]], label %[[SCALAR_PH:.*]], label %[[VECTOR_SCEVCHECK:.*]]
; CHECK: [[VECTOR_SCEVCHECK]]:
-; CHECK: [[TMP4:%.*]] = select i1 [[TMP3:%.*]], i8 [[TMP2:%.*]], i8 [[TMP1:%.*]]
-; CHECK: [[TMP9:%.*]] = select i1 [[TMP3]], i1 [[TMP8:%.*]], i1 [[TMP7:%.*]]
+; CHECK: [[TMP4:%.*]] = select i1 [[TMP3:%.*]], i8 [[TMP2:%.*]], i8 [[TMP1:%.*]], !prof [[PROF1:![0-9]+]]
+; CHECK: [[TMP9:%.*]] = select i1 [[TMP3]], i1 [[TMP8:%.*]], i1 [[TMP7:%.*]], !prof [[PROF1]]
; CHECK: br i1 [[TMP16:%.*]], label %[[SCALAR_PH]], label %[[VECTOR_PH:.*]]
; CHECK: [[VECTOR_PH]]:
; CHECK: [[VECTOR_BODY:.*]]:
@@ -57,12 +57,12 @@ define void @runtime_step_memcheck(ptr %in, ptr %out, i64 %n, i64 %step) !prof !
; CHECK: [[LOOP_PREHEADER]]:
; CHECK: br i1 [[MIN_ITERS_CHECK:%.*]], label %[[SCALAR_PH:.*]], label %[[VECTOR_SCEVCHECK:.*]]
; CHECK: [[VECTOR_SCEVCHECK]]:
-; CHECK: [[TMP4:%.*]] = select i1 [[TMP3:%.*]], i32 [[TMP2:%.*]], i32 [[TMP1:%.*]]
-; CHECK: [[TMP9:%.*]] = select i1 [[TMP3]], i1 [[TMP8:%.*]], i1 [[TMP7:%.*]]
+; CHECK: [[TMP4:%.*]] = select i1 [[TMP3:%.*]], i32 [[TMP2:%.*]], i32 [[TMP1:%.*]], !prof [[PROF1]]
+; CHECK: [[TMP9:%.*]] = select i1 [[TMP3]], i1 [[TMP8:%.*]], i1 [[TMP7:%.*]], !prof [[PROF1]]
; CHECK: br i1 [[TMP16:%.*]], label %[[SCALAR_PH]], label %[[VECTOR_MEMCHECK:.*]]
; CHECK: [[VECTOR_MEMCHECK]]:
-; CHECK: [[UMIN:%.*]] = select i1 [[TMP23:%.*]], ptr [[IN]], ptr [[SCEVGEP1:%.*]]
-; CHECK: [[UMAX:%.*]] = select i1 [[TMP24:%.*]], ptr [[IN]], ptr [[SCEVGEP1]]
+; CHECK: [[UMIN:%.*]] = select i1 [[TMP23:%.*]], ptr [[IN]], ptr [[SCEVGEP1:%.*]], !prof [[PROF1]]
+; CHECK: [[UMAX:%.*]] = select i1 [[TMP24:%.*]], ptr [[IN]], ptr [[SCEVGEP1]], !prof [[PROF1]]
; CHECK: br i1 [[FOUND_CONFLICT:%.*]], label %[[SCALAR_PH]], label %[[VECTOR_PH:.*]]
; CHECK: [[VECTOR_PH]]:
; CHECK: [[VECTOR_BODY:.*]]:
@@ -149,6 +149,7 @@ exit:
!0 = !{!"function_entry_count", i64 1000}
;.
; CHECK: [[PROF0]] = !{!"function_entry_count", i64 1000}
+; CHECK: [[PROF1]] = !{!"unknown", !"scev-expander"}
; CHECK: [[LOOP1]] = distinct !{[[LOOP1]], [[META2:![0-9]+]], [[META3:![0-9]+]]}
; CHECK: [[META2]] = !{!"llvm.loop.isvectorized", i32 1}
; CHECK: [[META3]] = !{!"llvm.loop.unroll.runtime.disable"}
More information about the llvm-commits
mailing list