Skip to content

Conversation

@nikic
Copy link
Contributor

@nikic nikic commented Dec 5, 2025

Add the missing skipFunction() call so that optnone attributes and opt-bisect-limit is respected.

Add the missing skipFunction() call so that optnone attributes
and opt-bisect-limit is respected.
@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2025

@llvm/pr-subscribers-backend-x86

Author: Nikita Popov (nikic)

Changes

Add the missing skipFunction() call so that optnone attributes and opt-bisect-limit is respected.


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

2 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectOptimize.cpp (+3)
  • (modified) llvm/test/CodeGen/X86/select-optimize.ll (+10)
diff --git a/llvm/lib/CodeGen/SelectOptimize.cpp b/llvm/lib/CodeGen/SelectOptimize.cpp
index 13ed8f28d5507..691dcd072679b 100644
--- a/llvm/lib/CodeGen/SelectOptimize.cpp
+++ b/llvm/lib/CodeGen/SelectOptimize.cpp
@@ -313,6 +313,9 @@ class SelectOptimize : public FunctionPass {
   }
 
   bool runOnFunction(Function &F) override {
+    if (skipFunction(F))
+      return false;
+
     return Impl.runOnFunction(F, *this);
   }
 
diff --git a/llvm/test/CodeGen/X86/select-optimize.ll b/llvm/test/CodeGen/X86/select-optimize.ll
index 6cb49f243ec69..b8f7f7578a3d1 100644
--- a/llvm/test/CodeGen/X86/select-optimize.ll
+++ b/llvm/test/CodeGen/X86/select-optimize.ll
@@ -23,6 +23,16 @@ define i32 @weighted_select1(i32 %a, i32 %b, i1 %cmp) {
   ret i32 %sel
 }
 
+; But don't do anything for optnone functions.
+define i32 @weighted_select1_optnone(i32 %a, i32 %b, i1 %cmp) optnone noinline {
+; CHECK-LABEL: @weighted_select1_optnone(
+; CHECK-NEXT:    [[SEL:%.*]] = select i1 [[CMP:%.*]], i32 [[A:%.*]], i32 [[B:%.*]], !prof [[PROF16]]
+; CHECK-NEXT:    ret i32 [[SEL]]
+;
+  %sel = select i1 %cmp, i32 %a, i32 %b, !prof !15
+  ret i32 %sel
+}
+
 ; If a select is obviously predictable (reversed profile weights),
 ; turn it into a branch.
 define i32 @weighted_select2(i32 %a, i32 %b, i1 %cmp) {

Copy link
Member

@dianqk dianqk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@nikic nikic merged commit ce1b047 into llvm:main Dec 15, 2025
13 checks passed
@nikic nikic deleted the select-optimize-optnone branch December 15, 2025 08:21
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.

4 participants