[llvm] [InstCombine] Mark select in fdiv transforms with unknown profile (PR #177759)

Aiden Grossman via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 24 04:54:35 PST 2026


https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/177759

>From 500fdb56bae5cf092c7ce801f828cdd375a6c9a5 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Sat, 24 Jan 2026 12:38:03 +0000
Subject: [PATCH 1/2] [InstCombine] Mark select in fdiv transforms with unknown
 profile

As part of the profcheck effort we are trying to explicitly annotate
select instructions where we cannot reasonably synthesize profile
information as having an unknown profile. This does that for the case
introduced in 0993d69bc35cfdd4f3a904a603701e66906e8987.
---
 .../Transforms/InstCombine/InstCombineSimplifyDemanded.cpp    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
index 899b52fdc951b..c9d16f08ae117 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
@@ -2533,11 +2533,11 @@ Value *InstCombinerImpl::SimplifyDemandedUseFPClass(Instruction *I,
 
       Value *IsInfOrZeroOrNan = Builder.CreateOr(IsInfOrNan, IsZeroOrNan);
 
-      return Builder.CreateSelectFMF(
+      return Builder.CreateSelectFMFWithUnknownProfile(
           IsInfOrZeroOrNan, ConstantFP::getQNaN(VTy),
           ConstantFP::get(
               VTy, APFloat::getOne(VTy->getScalarType()->getFltSemantics())),
-          FMF);
+          FMF, DEBUG_TYPE);
     }
 
     Type *EltTy = VTy->getScalarType();

>From de00fe3f824c315192db2b8669fb2d64e7866327 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Sat, 24 Jan 2026 12:54:24 +0000
Subject: [PATCH 2/2] Add test

---
 .../simplify-demanded-fpclass-fdiv.ll         | 20 +++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fdiv.ll b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fdiv.ll
index 89b36ad9bf511..ea06ccb4a3fb7 100644
--- a/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fdiv.ll
+++ b/llvm/test/Transforms/InstCombine/simplify-demanded-fpclass-fdiv.ll
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 6
 ; RUN: opt -S -passes=instcombine < %s | FileCheck %s
 
 declare nofpclass(nan inf sub norm) half @returns_zero()
@@ -243,11 +243,11 @@ define nofpclass(inf) half @ret_src_must_be_zero_or_nan_self_other_use_input1(ha
   ret half %div
 }
 
-define nofpclass(snan) half @ret_src_nonan_self(half noundef nofpclass(nan) %x) {
+define nofpclass(snan) half @ret_src_nonan_self(half noundef nofpclass(nan) %x) !prof !0 {
 ; CHECK-LABEL: define nofpclass(snan) half @ret_src_nonan_self(
-; CHECK-SAME: half noundef nofpclass(nan) [[X:%.*]]) {
+; CHECK-SAME: half noundef nofpclass(nan) [[X:%.*]]) !prof [[PROF0:![0-9]+]] {
 ; CHECK-NEXT:    [[TMP1:%.*]] = call i1 @llvm.is.fpclass.f16(half [[X]], i32 612)
-; CHECK-NEXT:    [[DIV:%.*]] = select i1 [[TMP1]], half 0xH7E00, half 0xH3C00
+; CHECK-NEXT:    [[DIV:%.*]] = select i1 [[TMP1]], half 0xH7E00, half 0xH3C00, !prof [[PROF1:![0-9]+]]
 ; CHECK-NEXT:    ret half [[DIV]]
 ;
   %div = fdiv half %x, %x
@@ -2299,3 +2299,15 @@ attributes #0 = { "denormal-fp-math"="preserve-sign,preserve-sign" }
 attributes #1 = { "denormal-fp-math"="dynamic,dynamic" }
 attributes #2 = { "denormal-fp-math"="ieee,preserve-sign" }
 attributes #3 = { "denormal-fp-math"="ieee,dynamic" }
+
+!0 = !{!"function_entry_count", i64 1000}
+;.
+; CHECK: attributes #[[ATTR0]] = { "denormal-fp-math"="ieee,preserve-sign" }
+; CHECK: attributes #[[ATTR1]] = { "denormal-fp-math"="preserve-sign,preserve-sign" }
+; CHECK: attributes #[[ATTR2]] = { "denormal-fp-math"="dynamic,dynamic" }
+; CHECK: attributes #[[ATTR3]] = { "denormal-fp-math"="ieee,dynamic" }
+; CHECK: attributes #[[ATTR4:[0-9]+]] = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }
+;.
+; CHECK: [[PROF0]] = !{!"function_entry_count", i64 1000}
+; CHECK: [[PROF1]] = !{!"unknown", !"instcombine"}
+;.



More information about the llvm-commits mailing list