Skip to content

Commit 8ce46b2

Browse files
committed
[NFC][InstCombine] Make use of unknown profile info clear in the API name
1 parent f949804 commit 8ce46b2

File tree

5 files changed

+24
-12
lines changed

5 files changed

+24
-12
lines changed

llvm/include/llvm/IR/Instructions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,7 +1715,7 @@ class SelectInst : public Instruction {
17151715
static SelectInst *Create(Value *C, Value *S1, Value *S2,
17161716
const Twine &NameStr = "",
17171717
InsertPosition InsertBefore = nullptr,
1718-
Instruction *MDFrom = nullptr) {
1718+
const Instruction *MDFrom = nullptr) {
17191719
SelectInst *Sel =
17201720
new (AllocMarker) SelectInst(C, S1, S2, NameStr, InsertBefore);
17211721
if (MDFrom)

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -880,11 +880,13 @@ Instruction *InstCombinerImpl::foldAddWithConstant(BinaryOperator &Add) {
880880
// zext(bool) + C -> bool ? C + 1 : C
881881
if (match(Op0, m_ZExt(m_Value(X))) &&
882882
X->getType()->getScalarSizeInBits() == 1)
883-
return createSelectInst(X, InstCombiner::AddOne(Op1C), Op1);
883+
return createSelectInstWithUnknownProfile(X, InstCombiner::AddOne(Op1C),
884+
Op1);
884885
// sext(bool) + C -> bool ? C - 1 : C
885886
if (match(Op0, m_SExt(m_Value(X))) &&
886887
X->getType()->getScalarSizeInBits() == 1)
887-
return createSelectInst(X, InstCombiner::SubOne(Op1C), Op1);
888+
return createSelectInstWithUnknownProfile(X, InstCombiner::SubOne(Op1C),
889+
Op1);
888890

889891
// ~X + C --> (C-1) - X
890892
if (match(Op0, m_Not(m_Value(X)))) {

llvm/lib/Transforms/InstCombine/InstCombineInternal.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,15 +470,24 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
470470
Value *simplifyNonNullOperand(Value *V, bool HasDereferenceable,
471471
unsigned Depth = 0);
472472

473+
/// Create `select C, S1, S2` and copy metadata from MDFrom.
473474
SelectInst *createSelectInst(Value *C, Value *S1, Value *S2,
475+
const Instruction &MDFrom,
474476
const Twine &NameStr = "",
475-
InsertPosition InsertBefore = nullptr,
476-
Instruction *MDFrom = nullptr) {
477-
SelectInst *SI =
478-
SelectInst::Create(C, S1, S2, NameStr, InsertBefore, MDFrom);
479-
if (!MDFrom)
480-
setExplicitlyUnknownBranchWeightsIfProfiled(*SI, F, DEBUG_TYPE);
481-
return SI;
477+
InsertPosition InsertBefore = nullptr) {
478+
return SelectInst::Create(C, S1, S2, NameStr, InsertBefore, &MDFrom);
479+
}
480+
481+
/// Use instead of createSelectInst if the profile cannot be calculated from
482+
/// existing profile metadata. If the Function has profiles, set the profile
483+
/// of this select to "unknown".
484+
SelectInst *
485+
createSelectInstWithUnknownProfile(Value *C, Value *S1, Value *S2,
486+
const Twine &NameStr = "",
487+
InsertPosition InsertBefore = nullptr) {
488+
auto *Sel = SelectInst::Create(C, S1, S2, NameStr, InsertBefore, nullptr);
489+
setExplicitlyUnknownBranchWeightsIfProfiled(*Sel, F, DEBUG_TYPE);
490+
return Sel;
482491
}
483492

484493
public:

llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,8 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) {
12531253
// shl (zext i1 X), C1 --> select (X, 1 << C1, 0)
12541254
if (match(Op0, m_ZExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) {
12551255
auto *NewC = Builder.CreateShl(ConstantInt::get(Ty, 1), C1);
1256-
return createSelectInst(X, NewC, ConstantInt::getNullValue(Ty));
1256+
return createSelectInstWithUnknownProfile(X, NewC,
1257+
ConstantInt::getNullValue(Ty));
12571258
}
12581259
}
12591260

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@ Instruction *InstCombinerImpl::foldBinopOfSextBoolToSelect(BinaryOperator &BO) {
17371737
Constant *Zero = ConstantInt::getNullValue(BO.getType());
17381738
Value *TVal = Builder.CreateBinOp(BO.getOpcode(), Ones, C);
17391739
Value *FVal = Builder.CreateBinOp(BO.getOpcode(), Zero, C);
1740-
return createSelectInst(X, TVal, FVal);
1740+
return createSelectInstWithUnknownProfile(X, TVal, FVal);
17411741
}
17421742

17431743
static Value *simplifyOperationIntoSelectOperand(Instruction &I, SelectInst *SI,

0 commit comments

Comments
 (0)