[llvm] [InstCombine] Keep branch weights when folding a shift through a select (PR #227987)

Alok Kumar Sharma via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 02:46:06 PDT 2026


================
@@ -994,7 +994,10 @@ Instruction *InstCombinerImpl::FoldShiftByConstant(Value *Op0, Constant *C1,
 
       Value *NewShift = Builder.CreateBinOp(I.getOpcode(), FalseVal, C1);
       Value *NewOp = Builder.CreateBinOp(TBO->getOpcode(), NewShift, NewRHS);
-      return SelectInst::Create(Cond, NewOp, NewShift);
+      auto *NewSel = SelectInst::Create(Cond, NewOp, NewShift);
+      if (auto *SI = dyn_cast<SelectInst>(Op0))
+        NewSel->copyMetadata(*SI, {LLVMContext::MD_prof});
+      return NewSel;
----------------
alokkrsharma wrote:

Done, thanks. I've switched to MDFrom now.

https://github.com/llvm/llvm-project/pull/227987


More information about the llvm-commits mailing list