https://github.com/snehasish updated 
https://github.com/llvm/llvm-project/pull/179767

>From 22b2f0ad8d1b0b839e02c1bf7888429a043e53e0 Mon Sep 17 00:00:00 2001
From: Snehasish Kumar <[email protected]>
Date: Tue, 3 Feb 2026 23:40:34 +0000
Subject: [PATCH 1/2] [InstCombine][profcheck] Fix missing profdata for zext
 transform.

---
 .../InstCombine/InstCombineAddSub.cpp         | 21 +++++++++++++++----
 .../InstCombine/zext-bool-add-sub.ll          | 14 ++++++++-----
 llvm/utils/profcheck-xfail.txt                |  1 -
 3 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 3ccc63d20eb23..085a96d170a55 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -22,6 +22,7 @@
 #include "llvm/IR/InstrTypes.h"
 #include "llvm/IR/Instruction.h"
 #include "llvm/IR/Instructions.h"
+#include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Operator.h"
 #include "llvm/IR/PatternMatch.h"
 #include "llvm/IR/Type.h"
@@ -2504,12 +2505,24 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator 
&I) {
 
   if (Constant *C = dyn_cast<Constant>(Op0)) {
     Value *X;
-    if (match(Op1, m_ZExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1))
+    if (match(Op1, m_ZExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) 
{
       // C - (zext bool) --> bool ? C - 1 : C
-      return SelectInst::Create(X, InstCombiner::SubOne(C), C);
-    if (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1))
+      SelectInst *SI = SelectInst::Create(X, InstCombiner::SubOne(C), C);
+      if (!ProfcheckDisableMetadataFixes && I.getFunction()->hasProfileData()) 
{
+        MDBuilder MDB(I.getContext());
+        SI->setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(1, 1));
+      }
+      return SI;
+    }
+    if (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) 
{
       // C - (sext bool) --> bool ? C + 1 : C
-      return SelectInst::Create(X, InstCombiner::AddOne(C), C);
+      SelectInst *SI = SelectInst::Create(X, InstCombiner::AddOne(C), C);
+      if (!ProfcheckDisableMetadataFixes && I.getFunction()->hasProfileData()) 
{
+        MDBuilder MDB(I.getContext());
+        SI->setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(1, 1));
+      }
+      return SI;
+    }
 
     // C - ~X == X + (1+C)
     if (match(Op1, m_Not(m_Value(X))))
diff --git a/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll 
b/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll
index 271c303664b72..a9e337e243f34 100644
--- a/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll
+++ b/llvm/test/Transforms/InstCombine/zext-bool-add-sub.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 smart
 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
 
 ; rdar://11748024
@@ -146,10 +146,10 @@ define i64 @zext_sub_const(i1 %A) {
   ret i64 %sub
 }
 
-define i64 @zext_sub_const_extra_use(i1 %A) {
+define i64 @zext_sub_const_extra_use(i1 %A) !prof !0 {
 ; CHECK-LABEL: @zext_sub_const_extra_use(
 ; CHECK-NEXT:    [[EXT:%.*]] = zext i1 [[A:%.*]] to i64
-; CHECK-NEXT:    [[SUB:%.*]] = select i1 [[A]], i64 41, i64 42
+; CHECK-NEXT:    [[SUB:%.*]] = select i1 [[A]], i64 41, i64 42, !prof 
[[PROF1:![0-9]+]]
 ; CHECK-NEXT:    call void @use(i64 [[EXT]])
 ; CHECK-NEXT:    ret i64 [[SUB]]
 ;
@@ -232,10 +232,10 @@ define i64 @sext_sub_const(i1 %A) {
   ret i64 %sub
 }
 
-define i64 @sext_sub_const_extra_use(i1 %A) {
+define i64 @sext_sub_const_extra_use(i1 %A) !prof !0 {
 ; CHECK-LABEL: @sext_sub_const_extra_use(
 ; CHECK-NEXT:    [[EXT:%.*]] = sext i1 [[A:%.*]] to i64
-; CHECK-NEXT:    [[SUB:%.*]] = select i1 [[A]], i64 43, i64 42
+; CHECK-NEXT:    [[SUB:%.*]] = select i1 [[A]], i64 43, i64 42, !prof [[PROF1]]
 ; CHECK-NEXT:    call void @use(i64 [[EXT]])
 ; CHECK-NEXT:    ret i64 [[SUB]]
 ;
@@ -402,3 +402,7 @@ define <4 x i32> @zextbool_sub_vector(<4 x i1> %c, <4 x 
i32> %x) {
   ret <4 x i32> %s
 }
 
+!0 = !{!"function_entry_count", i64 1000}
+;.
+; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 1}
+;.
diff --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt
index 7f5a68c37338e..0ba8b2f7ec30c 100644
--- a/llvm/utils/profcheck-xfail.txt
+++ b/llvm/utils/profcheck-xfail.txt
@@ -260,7 +260,6 @@ Transforms/InstCombine/wcslen-3.ll
 Transforms/InstCombine/X86/x86-avx512-inseltpoison.ll
 Transforms/InstCombine/X86/x86-avx512.ll
 Transforms/InstCombine/xor-and-or.ll
-Transforms/InstCombine/zext-bool-add-sub.ll
 Transforms/IROutliner/alloca-addrspace-1.ll
 Transforms/IROutliner/alloca-addrspace.ll
 Transforms/IROutliner/different-intrinsics.ll

>From da0d536a6e7ab9b8664adbcd97d9e9101dabc799 Mon Sep 17 00:00:00 2001
From: Snehasish Kumar <[email protected]>
Date: Wed, 4 Feb 2026 01:34:11 +0000
Subject: [PATCH 2/2] [InstCombine][profcheck] Fix missing profdata for
 zext/sext transform and update tests

---
 .../InstCombine/InstCombineAddSub.cpp         | 20 +++-----
 .../InstCombine/zext-bool-add-sub.ll          |  2 +-
 llvm/utils/profcheck-xfail.txt                | 49 -------------------
 3 files changed, 9 insertions(+), 62 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 085a96d170a55..4d87b6a7938a9 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -2507,21 +2507,17 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator 
&I) {
     Value *X;
     if (match(Op1, m_ZExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) 
{
       // C - (zext bool) --> bool ? C - 1 : C
-      SelectInst *SI = SelectInst::Create(X, InstCombiner::SubOne(C), C);
-      if (!ProfcheckDisableMetadataFixes && I.getFunction()->hasProfileData()) 
{
-        MDBuilder MDB(I.getContext());
-        SI->setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(1, 1));
-      }
-      return SI;
+      if (!ProfcheckDisableMetadataFixes)
+        return createSelectInstWithUnknownProfile(X, InstCombiner::SubOne(C),
+                                                  C);
+      return SelectInst::Create(X, InstCombiner::SubOne(C), C);
     }
     if (match(Op1, m_SExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) 
{
       // C - (sext bool) --> bool ? C + 1 : C
-      SelectInst *SI = SelectInst::Create(X, InstCombiner::AddOne(C), C);
-      if (!ProfcheckDisableMetadataFixes && I.getFunction()->hasProfileData()) 
{
-        MDBuilder MDB(I.getContext());
-        SI->setMetadata(LLVMContext::MD_prof, MDB.createBranchWeights(1, 1));
-      }
-      return SI;
+      if (!ProfcheckDisableMetadataFixes)
+        return createSelectInstWithUnknownProfile(X, InstCombiner::AddOne(C),
+                                                  C);
+      return SelectInst::Create(X, InstCombiner::AddOne(C), C);
     }
 
     // C - ~X == X + (1+C)
diff --git a/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll 
b/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll
index a9e337e243f34..bebe0177ba030 100644
--- a/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll
+++ b/llvm/test/Transforms/InstCombine/zext-bool-add-sub.ll
@@ -404,5 +404,5 @@ define <4 x i32> @zextbool_sub_vector(<4 x i1> %c, <4 x 
i32> %x) {
 
 !0 = !{!"function_entry_count", i64 1000}
 ;.
-; CHECK: [[PROF1]] = !{!"branch_weights", i32 1, i32 1}
+; CHECK: [[PROF1]] = !{!"unknown", !"instcombine"}
 ;.
diff --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt
index 0ba8b2f7ec30c..ce21e1b24eaec 100644
--- a/llvm/utils/profcheck-xfail.txt
+++ b/llvm/utils/profcheck-xfail.txt
@@ -207,56 +207,7 @@ Transforms/IndVarSimplify/invalidate-modified-lcssa-phi.ll
 Transforms/IndVarSimplify/pr45835.ll
 Transforms/IndVarSimplify/preserving-debugloc-rem-div.ll
 Transforms/InstCombine/2004-09-20-BadLoadCombine.ll
-Transforms/InstCombine/apint-div1.ll
-Transforms/InstCombine/apint-div2.ll
-Transforms/InstCombine/atomic.ll
-Transforms/InstCombine/binop-cast.ll
-Transforms/InstCombine/binop-select-cast-of-select-cond.ll
-Transforms/InstCombine/bit-checks.ll
-Transforms/InstCombine/canonicalize-clamp-like-pattern-between-zero-and-positive-threshold.ll
-Transforms/InstCombine/cttz.ll
-Transforms/InstCombine/div.ll
-Transforms/InstCombine/div-shift.ll
-Transforms/InstCombine/fcmp-select.ll
-Transforms/InstCombine/ffs-i16.ll
-Transforms/InstCombine/intrinsic-select.ll
-Transforms/InstCombine/load-bitcast-select.ll
-Transforms/InstCombine/load.ll
-Transforms/InstCombine/load-select.ll
-Transforms/InstCombine/loadstore-metadata.ll
-Transforms/InstCombine/logical-select.ll
-Transforms/InstCombine/memchr-3.ll
-Transforms/InstCombine/memchr-6.ll
-Transforms/InstCombine/memchr-7.ll
-Transforms/InstCombine/memchr-9.ll
-Transforms/InstCombine/memchr.ll
-Transforms/InstCombine/mem-gep-zidx.ll
-Transforms/InstCombine/memrchr-3.ll
-Transforms/InstCombine/memrchr-4.ll
-Transforms/InstCombine/minmax-fp.ll
-Transforms/InstCombine/minmax-intrinsics.ll
-Transforms/InstCombine/mul-inseltpoison.ll
-Transforms/InstCombine/mul.ll
-Transforms/InstCombine/mul-pow2.ll
-Transforms/InstCombine/multiple-uses-load-bitcast-select.ll
-Transforms/InstCombine/or-fcmp.ll
-Transforms/InstCombine/pow-1.ll
-Transforms/InstCombine/pow-3.ll
-Transforms/InstCombine/pow-sqrt.ll
-Transforms/InstCombine/select-min-max.ll
-Transforms/InstCombine/shift.ll
-Transforms/InstCombine/simplify-demanded-fpclass.ll
-Transforms/InstCombine/sink-not-into-another-hand-of-logical-and.ll
-Transforms/InstCombine/sink-not-into-another-hand-of-logical-or.ll
-Transforms/InstCombine/strchr-1.ll
-Transforms/InstCombine/strchr-3.ll
-Transforms/InstCombine/strlen-1.ll
-Transforms/InstCombine/strrchr-3.ll
 Transforms/InstCombine/sub-xor-cmp.ll
-Transforms/InstCombine/truncating-saturate.ll
-Transforms/InstCombine/unordered-fcmp-select.ll
-Transforms/InstCombine/wcslen-1.ll
-Transforms/InstCombine/wcslen-3.ll
 Transforms/InstCombine/X86/x86-avx512-inseltpoison.ll
 Transforms/InstCombine/X86/x86-avx512.ll
 Transforms/InstCombine/xor-and-or.ll

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to