https://github.com/snehasish updated https://github.com/llvm/llvm-project/pull/179741
>From dbb4e81c949c0ef3226794ff28efd90342d9f402 Mon Sep 17 00:00:00 2001 From: Snehasish Kumar <[email protected]> Date: Mon, 2 Feb 2026 22:14:10 +0000 Subject: [PATCH] Fix profcheck failure in Transforms/InstCombine/and2.ll --- .../InstCombine/InstCombineSelect.cpp | 14 ++++++++--- llvm/test/Transforms/InstCombine/and2.ll | 25 ++++++++++++------- llvm/utils/profcheck-xfail.txt | 1 - 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index fb30a4545cffe..efce806cc2c68 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -3454,8 +3454,11 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) { // poison. if (match(TrueVal, m_One())) { if (impliesPoisonOrCond(FalseVal, CondVal, /*Expected=*/false)) { - // Change: A = select B, true, C --> A = or B, C - return BinaryOperator::CreateOr(CondVal, FalseVal); + if (ProfcheckDisableMetadataFixes || + !SI.hasMetadata(LLVMContext::MD_prof)) { + // Change: A = select B, true, C --> A = or B, C + return BinaryOperator::CreateOr(CondVal, FalseVal); + } } if (match(CondVal, m_OneUse(m_Select(m_Value(A), m_One(), m_Value(B)))) && @@ -3499,8 +3502,11 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) { if (match(FalseVal, m_Zero())) { if (impliesPoisonOrCond(TrueVal, CondVal, /*Expected=*/true)) { - // Change: A = select B, C, false --> A = and B, C - return BinaryOperator::CreateAnd(CondVal, TrueVal); + if (ProfcheckDisableMetadataFixes || + !SI.hasMetadata(LLVMContext::MD_prof)) { + // Change: A = select B, C, false --> A = and B, C + return BinaryOperator::CreateAnd(CondVal, TrueVal); + } } if (match(CondVal, m_OneUse(m_Select(m_Value(A), m_Value(B), m_Zero()))) && diff --git a/llvm/test/Transforms/InstCombine/and2.ll b/llvm/test/Transforms/InstCombine/and2.ll index ce49f4e8f6f12..d495d90c6362d 100644 --- a/llvm/test/Transforms/InstCombine/and2.ll +++ b/llvm/test/Transforms/InstCombine/and2.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 define i1 @test2(i1 %X, i1 %Y) { @@ -13,11 +13,12 @@ define i1 @test2(i1 %X, i1 %Y) { define i1 @test2_logical(i1 %X, i1 %Y) { ; CHECK-LABEL: @test2_logical( -; CHECK-NEXT: [[A:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false +; CHECK-NEXT: [[A1:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false, !prof [[PROF0:![0-9]+]] +; CHECK-NEXT: [[A:%.*]] = select i1 [[A1]], i1 [[X]], i1 false, !prof [[PROF0]] ; CHECK-NEXT: ret i1 [[A]] ; - %a = select i1 %X, i1 %Y, i1 false - %b = select i1 %a, i1 %X, i1 false + %a = select i1 %X, i1 %Y, i1 false, !prof !0 + %b = select i1 %a, i1 %X, i1 false, !prof !0 ret i1 %b } @@ -46,14 +47,16 @@ define i1 @test7(i32 %i, i1 %b) { define i1 @test7_logical(i32 %i, i1 %b) { ; CHECK-LABEL: @test7_logical( -; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[I:%.*]], 0 -; CHECK-NEXT: [[AND2:%.*]] = select i1 [[TMP1]], i1 [[B:%.*]], i1 false +; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[I:%.*]], 1 +; CHECK-NEXT: [[CMP2:%.*]] = icmp sgt i32 [[I]], -1 +; CHECK-NEXT: [[AND1:%.*]] = select i1 [[CMP1]], i1 [[B:%.*]], i1 false, !prof [[PROF0]] +; CHECK-NEXT: [[AND2:%.*]] = select i1 [[AND1]], i1 [[CMP2]], i1 false, !prof [[PROF0]] ; CHECK-NEXT: ret i1 [[AND2]] ; %cmp1 = icmp slt i32 %i, 1 %cmp2 = icmp sgt i32 %i, -1 - %and1 = select i1 %cmp1, i1 %b, i1 false - %and2 = select i1 %and1, i1 %cmp2, i1 false + %and1 = select i1 %cmp1, i1 %b, i1 false, !prof !0 + %and2 = select i1 %and1, i1 %cmp2, i1 false, !prof !0 ret i1 %and2 } @@ -77,7 +80,7 @@ define i1 @test8_logical(i32 %i) { ; %cmp1 = icmp ne i32 %i, 0 %cmp2 = icmp ult i32 %i, 14 - %cond = select i1 %cmp1, i1 %cmp2, i1 false + %cond = select i1 %cmp1, i1 %cmp2, i1 false, !prof !0 ret i1 %cond } @@ -285,3 +288,7 @@ define i32 @test14(i32 %a, i32 %b) { %w = mul i32 %z, %x ; to keep the shift from being removed ret i32 %w } +!0 = !{!"branch_weights", i32 1, i32 1} +;. +; CHECK: [[PROF0]] = !{!"branch_weights", i32 1, i32 1} +;. diff --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt index e88cfc0d6580c..8f39c3c5cdda6 100644 --- a/llvm/utils/profcheck-xfail.txt +++ b/llvm/utils/profcheck-xfail.txt @@ -207,7 +207,6 @@ 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/and2.ll Transforms/InstCombine/and-fcmp.ll Transforms/InstCombine/and-or-icmps.ll Transforms/InstCombine/atomic.ll _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
