aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSnehasish Kumar <snehasishk@google.com>2026-02-03 05:16:27 +0000
committerSnehasish Kumar <snehasishk@google.com>2026-02-10 22:50:09 +0000
commit5aa88ac52e2867fe98e3e55d8a14465ab54b2633 (patch)
tree0f8b936327ed0588758fcb65a728bb7e005179bf
parentac8966499b8d9ada5e25165b59e8a2bb2159983a (diff)
downloadllvm-users/snehasish/fix-shift-select-prof.tar.gz
llvm-users/snehasish/fix-shift-select-prof.tar.bz2
llvm-users/snehasish/fix-shift-select-prof.zip
InstCombine: Propagate profile metadata in shift-of-select foldingusers/snehasish/fix-shift-select-prof
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp3
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp10
-rw-r--r--llvm/lib/Transforms/InstCombine/InstructionCombining.cpp3
-rw-r--r--llvm/utils/profcheck-xfail.txt1
4 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index eef0081a2dd2..16df6a93344d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1781,6 +1781,9 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
Ext->hasOneUse()) {
Value *Add = isa<ZExtInst>(Ext) ? InstCombiner::AddOne(C)
: InstCombiner::SubOne(C);
+ if (!ProfcheckDisableMetadataFixes)
+ return replaceInstUsesWith(
+ I, createSelectInstWithUnknownProfile(Cond, Add, A));
return replaceInstUsesWith(I, Builder.CreateSelect(Cond, Add, A));
}
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 1905f2b30f9b..fc77a37fb446 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -893,7 +893,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);
+ SelectInst *NewSI = SelectInst::Create(Cond, NewOp, NewShift);
+ if (!ProfcheckDisableMetadataFixes)
+ NewSI->copyMetadata(*cast<SelectInst>(Op0));
+ return NewSI;
}
}
@@ -910,7 +913,10 @@ Instruction *InstCombinerImpl::FoldShiftByConstant(Value *Op0, Constant *C1,
Value *NewShift = Builder.CreateBinOp(I.getOpcode(), TrueVal, C1);
Value *NewOp = Builder.CreateBinOp(FBO->getOpcode(), NewShift, NewRHS);
- return SelectInst::Create(Cond, NewShift, NewOp);
+ SelectInst *NewSI = SelectInst::Create(Cond, NewShift, NewOp);
+ if (!ProfcheckDisableMetadataFixes)
+ NewSI->copyMetadata(*cast<SelectInst>(Op0));
+ return NewSI;
}
}
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index e2bda2450c66..46b5d5584205 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -4699,7 +4699,8 @@ static Value *foldFrexpOfSelect(ExtractValueInst &EV, IntrinsicInst *FrexpCall,
Value *NewSel = Builder.CreateSelectFMF(
Cond, ConstIsTrue ? ConstantMantissa : NewEV,
- ConstIsTrue ? NewEV : ConstantMantissa, SelectInst, "select.frexp");
+ ConstIsTrue ? NewEV : ConstantMantissa, SelectInst, "select.frexp",
+ ProfcheckDisableMetadataFixes ? nullptr : SelectInst);
return NewSel;
}
Instruction *InstCombinerImpl::visitExtractValueInst(ExtractValueInst &EV) {
diff --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt
index 7f0c105286df..e3c4a8dfcbab 100644
--- a/llvm/utils/profcheck-xfail.txt
+++ b/llvm/utils/profcheck-xfail.txt
@@ -244,7 +244,6 @@ Transforms/InstCombine/or-fcmp.ll
Transforms/InstCombine/pow-1.ll
Transforms/InstCombine/pow-3.ll
Transforms/InstCombine/pow-sqrt.ll
-Transforms/InstCombine/pull-conditional-binop-through-shift.ll
Transforms/InstCombine/select-factorize.ll
Transforms/InstCombine/select-min-max.ll
Transforms/InstCombine/select-of-symmetric-selects.ll