[llvm] 06bfa42 - [ScalarizeMaskedMemIntrin][ProfCheck] Correctly annotate branch weights (part 2) (#219286)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 27 20:36:43 PDT 2026


Author: Yonah Goldberg
Date: 2026-08-27T20:36:36-07:00
New Revision: 06bfa42c66dea409a9737f9679260ff51425d5b3

URL: https://github.com/llvm/llvm-project/commit/06bfa42c66dea409a9737f9679260ff51425d5b3
DIFF: https://github.com/llvm/llvm-project/commit/06bfa42c66dea409a9737f9679260ff51425d5b3.diff

LOG: [ScalarizeMaskedMemIntrin][ProfCheck] Correctly annotate branch weights (part 2) (#219286)

https://github.com/llvm/llvm-project/pull/218753 broke LLVM CI because
it added a new test in `ScalarizeMaskedMemIntrin` that was not opted out
of during profcheck. Profcheck failed because this pass creates new
branches that did not attach branch weight metadata. We don't have any
information on the distribution of masks at runtime, so we have to mark
branch weights as explicitly unknown.

This basically extends https://github.com/llvm/llvm-project/pull/181568,
Aiden am I missing something for why you didn't add the branch weight
metadata for all branch creation before?

Tested the `ScalarizeMaskedMemIntrin` tests with profcheck locally and
they all pass.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
    llvm/utils/profcheck-xfail.txt

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp b/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
index be5e58125081f..432b079051d80 100644
--- a/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
+++ b/llvm/lib/Transforms/Scalar/ScalarizeMaskedMemIntrin.cpp
@@ -277,9 +277,13 @@ static void scalarizeMaskedLoad(const DataLayout &DL, bool HasBranchDivergence,
   if (isSplatValue(Mask, /*Index=*/0)) {
     Value *Predicate = Builder.CreateExtractElement(Mask, uint64_t(0ull),
                                                     Mask->getName() + ".first");
+    // We mark the branch weights as explicitly unknown given they would only
+    // be derivable from the mask which we do not have VP information for.
     Instruction *ThenTerm =
         SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
-                                  /*BranchWeights=*/nullptr, DTU);
+                                  getExplicitlyUnknownBranchWeightsIfProfiled(
+                                      *CI->getFunction(), DEBUG_TYPE),
+                                  DTU);
 
     BasicBlock *CondBlock = ThenTerm->getParent();
     CondBlock->setName("cond.load");
@@ -336,9 +340,13 @@ static void scalarizeMaskedLoad(const DataLayout &DL, bool HasBranchDivergence,
     //  %Elt = load i32* %EltAddr
     //  VResult = insertelement <16 x i32> VResult, i32 %Elt, i32 Idx
     //
+    // We mark the branch weights as explicitly unknown given they would only
+    // be derivable from the mask which we do not have VP information for.
     Instruction *ThenTerm =
         SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
-                                  /*BranchWeights=*/nullptr, DTU);
+                                  getExplicitlyUnknownBranchWeightsIfProfiled(
+                                      *CI->getFunction(), DEBUG_TYPE),
+                                  DTU);
 
     BasicBlock *CondBlock = ThenTerm->getParent();
     CondBlock->setName("cond.load");
@@ -453,9 +461,13 @@ static void scalarizeMaskedStore(const DataLayout &DL, bool HasBranchDivergence,
   if (isSplatValue(Mask, /*Index=*/0)) {
     Value *Predicate = Builder.CreateExtractElement(Mask, uint64_t(0ull),
                                                     Mask->getName() + ".first");
+    // We mark the branch weights as explicitly unknown given they would only
+    // be derivable from the mask which we do not have VP information for.
     Instruction *ThenTerm =
         SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
-                                  /*BranchWeights=*/nullptr, DTU);
+                                  getExplicitlyUnknownBranchWeightsIfProfiled(
+                                      *CI->getFunction(), DEBUG_TYPE),
+                                  DTU);
     BasicBlock *CondBlock = ThenTerm->getParent();
     CondBlock->setName("cond.store");
     Builder.SetInsertPoint(CondBlock->getTerminator());
@@ -507,9 +519,13 @@ static void scalarizeMaskedStore(const DataLayout &DL, bool HasBranchDivergence,
     //  %EltAddr = getelementptr i32* %1, i32 0
     //  %store i32 %OneElt, i32* %EltAddr
     //
+    // We mark the branch weights as explicitly unknown given they would only
+    // be derivable from the mask which we do not have VP information for.
     Instruction *ThenTerm =
         SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
-                                  /*BranchWeights=*/nullptr, DTU);
+                                  getExplicitlyUnknownBranchWeightsIfProfiled(
+                                      *CI->getFunction(), DEBUG_TYPE),
+                                  DTU);
 
     BasicBlock *CondBlock = ThenTerm->getParent();
     CondBlock->setName("cond.store");
@@ -905,9 +921,13 @@ static void scalarizeMaskedExpandLoad(const DataLayout &DL,
     //  %Elt = load i32* %EltAddr
     //  VResult = insertelement <16 x i32> VResult, i32 %Elt, i32 Idx
     //
+    // We mark the branch weights as explicitly unknown given they would only
+    // be derivable from the mask which we do not have VP information for.
     Instruction *ThenTerm =
         SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
-                                  /*BranchWeights=*/nullptr, DTU);
+                                  getExplicitlyUnknownBranchWeightsIfProfiled(
+                                      *CI->getFunction(), DEBUG_TYPE),
+                                  DTU);
 
     BasicBlock *CondBlock = ThenTerm->getParent();
     CondBlock->setName("cond.load");
@@ -1031,9 +1051,13 @@ static void scalarizeMaskedCompressStore(const DataLayout &DL,
     //  %EltAddr = getelementptr i32* %1, i32 0
     //  %store i32 %OneElt, i32* %EltAddr
     //
+    // We mark the branch weights as explicitly unknown given they would only
+    // be derivable from the mask which we do not have VP information for.
     Instruction *ThenTerm =
         SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
-                                  /*BranchWeights=*/nullptr, DTU);
+                                  getExplicitlyUnknownBranchWeightsIfProfiled(
+                                      *CI->getFunction(), DEBUG_TYPE),
+                                  DTU);
 
     BasicBlock *CondBlock = ThenTerm->getParent();
     CondBlock->setName("cond.store");
@@ -1140,9 +1164,13 @@ static void scalarizeMaskedVectorHistogram(const DataLayout &DL, CallInst *CI,
     Value *Predicate =
         Builder.CreateExtractElement(Mask, Idx, "Mask" + Twine(Idx));
 
+    // We mark the branch weights as explicitly unknown given they would only
+    // be derivable from the mask which we do not have VP information for.
     Instruction *ThenTerm =
         SplitBlockAndInsertIfThen(Predicate, InsertPt, /*Unreachable=*/false,
-                                  /*BranchWeights=*/nullptr, DTU);
+                                  getExplicitlyUnknownBranchWeightsIfProfiled(
+                                      *CI->getFunction(), DEBUG_TYPE),
+                                  DTU);
 
     BasicBlock *CondBlock = ThenTerm->getParent();
     CondBlock->setName("cond.histogram.update");

diff  --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt
index f058bcd329380..abf169d7f39ff 100644
--- a/llvm/utils/profcheck-xfail.txt
+++ b/llvm/utils/profcheck-xfail.txt
@@ -109,13 +109,6 @@ Transforms/PreISelIntrinsicLowering/AArch64/expand-exp.ll
 Transforms/PreISelIntrinsicLowering/AArch64/expand-fp-math.ll
 Transforms/PreISelIntrinsicLowering/AArch64/expand-fp-math-binary.ll
 Transforms/PreISelIntrinsicLowering/AArch64/expand-log.ll
-Transforms/ScalarizeMaskedMemIntrin/AArch64/expand-masked-load.ll
-Transforms/ScalarizeMaskedMemIntrin/AArch64/expand-masked-store.ll
-Transforms/ScalarizeMaskedMemIntrin/X86/expand-masked-compressstore.ll
-Transforms/ScalarizeMaskedMemIntrin/X86/expand-masked-expandload.ll
-Transforms/ScalarizeMaskedMemIntrin/X86/expand-masked-load.ll
-Transforms/ScalarizeMaskedMemIntrin/X86/expand-masked-store.ll
-Transforms/ScalarizeMaskedMemIntrin/X86/metadata.ll
 Transforms/StackProtector/cross-dso-cfi-stack-chk-fail.ll
 Transforms/TailCallElim/2010-06-26-MultipleReturnValues.ll
 Transforms/TailCallElim/accum_recursion.ll


        


More information about the llvm-commits mailing list