Skip to content

Commit e9f31b8

Browse files
mtrofinDharuniRAcharya
authored andcommitted
[NFC][InstCombine] Make use of unknown profile info clear in the API name (llvm#162766)
Making the choice more clear from the API name, otherwise it'd be very easy for one to just "not bother" with the `MDFrom`​, especially since it is optional and follows the optional `Name`​ - but this time we'd have a harder time detecting it's effectivelly dropped metadata.
1 parent 8fc6691 commit e9f31b8

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
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: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,16 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
471471
Value *simplifyNonNullOperand(Value *V, bool HasDereferenceable,
472472
unsigned Depth = 0);
473473

474-
SelectInst *createSelectInst(Value *C, Value *S1, Value *S2,
475-
const Twine &NameStr = "",
476-
InsertPosition InsertBefore = nullptr,
477-
Instruction *MDFrom = nullptr) {
478-
SelectInst *SI =
479-
SelectInst::Create(C, S1, S2, NameStr, InsertBefore, MDFrom);
480-
if (!MDFrom)
481-
setExplicitlyUnknownBranchWeightsIfProfiled(*SI, F, DEBUG_TYPE);
482-
return SI;
474+
/// Create `select C, S1, S2`. Use only when the profile cannot be calculated
475+
/// from existing profile metadata: if the Function has profiles, this will
476+
/// set the profile of this select to "unknown".
477+
SelectInst *
478+
createSelectInstWithUnknownProfile(Value *C, Value *S1, Value *S2,
479+
const Twine &NameStr = "",
480+
InsertPosition InsertBefore = nullptr) {
481+
auto *Sel = SelectInst::Create(C, S1, S2, NameStr, InsertBefore, nullptr);
482+
setExplicitlyUnknownBranchWeightsIfProfiled(*Sel, F, DEBUG_TYPE);
483+
return Sel;
483484
}
484485

485486
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)