[llvm] [InstCombine] Preserve profile after folding select instructions with conditionals (PR #159666)
    Mircea Trofin via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Wed Sep 24 08:29:11 PDT 2025
    
    
  
================
@@ -4521,8 +4522,21 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
   auto FoldSelectWithAndOrCond = [&](bool IsAnd, Value *A,
                                      Value *B) -> Instruction * {
     if (Value *V = simplifySelectInst(B, TrueVal, FalseVal,
-                                      SQ.getWithInstruction(&SI)))
-      return SelectInst::Create(A, IsAnd ? V : TrueVal, IsAnd ? FalseVal : V);
+                                      SQ.getWithInstruction(&SI))) {
+      Value *NewTrueVal = IsAnd ? V : TrueVal;
+      Value *NewFalseVal = IsAnd ? FalseVal : V;
+
+      // If the True and False values don't change, then preserve the branch
----------------
mtrofin wrote:
Neat! IIUC we can't determine the probability of the new condition because we only have the composite probability, but you're saying, if the values selected don't change, then the probability won't change, right?
Could the values get flipped, in which case you'd know the probability, too?
https://github.com/llvm/llvm-project/pull/159666
    
    
More information about the llvm-commits
mailing list