diff options
| author | Snehasish Kumar <snehasishk@google.com> | 2026-02-03 22:49:38 +0000 |
|---|---|---|
| committer | Snehasish Kumar <snehasishk@google.com> | 2026-02-10 22:50:09 +0000 |
| commit | d4c225fc668ebf1a6108bd9824199d0bb37bc8a4 (patch) | |
| tree | 6fbd1e2a22ebe28863cde5f413d14fef96a758c1 | |
| parent | 6ecba1c86d70103b86fe3cc04551d0406b585d07 (diff) | |
| download | llvm-users/snehasish/fix-select-select-prof.tar.gz llvm-users/snehasish/fix-select-select-prof.tar.bz2 llvm-users/snehasish/fix-select-select-prof.zip | |
InstCombine: Propagate profile metadata in logical op creation and select foldingusers/snehasish/fix-select-select-prof
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | 10 | ||||
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp | 12 | ||||
| -rw-r--r-- | llvm/utils/profcheck-xfail.txt | 1 |
3 files changed, 20 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp index 1377bd6190b3..0d40ac997ba6 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp @@ -5043,8 +5043,14 @@ bool InstCombinerImpl::sinkNotIntoOtherHandOfLogicalOp(Instruction &I) { Value *NewBinOp; if (IsBinaryOp) NewBinOp = Builder.CreateBinOp(NewOpc, Op0, Op1, I.getName() + ".not"); - else - NewBinOp = Builder.CreateLogicalOp(NewOpc, Op0, Op1, I.getName() + ".not"); + else { + NewBinOp = + Builder.CreateLogicalOp(NewOpc, Op0, Op1, I.getName() + ".not", + ProfcheckDisableMetadataFixes ? nullptr : &I); + if (!ProfcheckDisableMetadataFixes) + if (SelectInst *SI = dyn_cast<SelectInst>(NewBinOp)) + SI->swapProfMetadata(); + } replaceInstUsesWith(I, NewBinOp); // We can not just create an outer `not`, it will most likely be immediately // folded back, reconstructing our initial pattern, and causing an diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 2ddc1919f20e..897624b0df26 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -4702,6 +4702,9 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { And = Builder.CreateLogicalAnd(CondVal, TrueSI->getCondition(), "", ProfcheckDisableMetadataFixes ? nullptr : &SI); + if (!ProfcheckDisableMetadataFixes) + if (auto *I = dyn_cast<Instruction>(And)) + setExplicitlyUnknownBranchWeightsIfProfiled(*I, DEBUG_TYPE, &F); OtherVal = TrueSI->getTrueValue(); } // select(C0, select(C1, b, a), b) -> select(C0&&!C1, a, b) @@ -4710,6 +4713,9 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { And = Builder.CreateLogicalAnd(CondVal, InvertedCond, "", ProfcheckDisableMetadataFixes ? nullptr : &SI); + if (!ProfcheckDisableMetadataFixes) + if (auto *I = dyn_cast<Instruction>(And)) + setExplicitlyUnknownBranchWeightsIfProfiled(*I, DEBUG_TYPE, &F); OtherVal = TrueSI->getFalseValue(); } if (And && OtherVal) { @@ -4737,6 +4743,9 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { Or = Builder.CreateLogicalOr(CondVal, FalseSI->getCondition(), "", ProfcheckDisableMetadataFixes ? nullptr : &SI); + if (!ProfcheckDisableMetadataFixes) + if (auto *I = dyn_cast<Instruction>(Or)) + setExplicitlyUnknownBranchWeightsIfProfiled(*I, DEBUG_TYPE, &F); OtherVal = FalseSI->getFalseValue(); } // select(C0, a, select(C1, b, a)) -> select(C0||!C1, a, b) @@ -4745,6 +4754,9 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) { Or = Builder.CreateLogicalOr(CondVal, InvertedCond, "", ProfcheckDisableMetadataFixes ? nullptr : &SI); + if (!ProfcheckDisableMetadataFixes) + if (auto *I = dyn_cast<Instruction>(Or)) + setExplicitlyUnknownBranchWeightsIfProfiled(*I, DEBUG_TYPE, &F); OtherVal = FalseSI->getTrueValue(); } if (Or && OtherVal) { diff --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt index cdd69f7a686a..6644dc41b9cb 100644 --- a/llvm/utils/profcheck-xfail.txt +++ b/llvm/utils/profcheck-xfail.txt @@ -245,7 +245,6 @@ Transforms/InstCombine/pow-1.ll Transforms/InstCombine/pow-3.ll Transforms/InstCombine/pow-sqrt.ll Transforms/InstCombine/select-min-max.ll -Transforms/InstCombine/select-select.ll Transforms/InstCombine/shift.ll Transforms/InstCombine/simplify-demanded-fpclass.ll Transforms/InstCombine/sink-not-into-another-hand-of-logical-and.ll |
