mirror of
https://github.com/intel/llvm.git
synced 2026-01-14 03:50:17 +08:00
[NFC][InstCombine] Make use of unknown profile info clear in the API name (#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.
This commit is contained in:
@@ -1715,7 +1715,7 @@ public:
|
||||
static SelectInst *Create(Value *C, Value *S1, Value *S2,
|
||||
const Twine &NameStr = "",
|
||||
InsertPosition InsertBefore = nullptr,
|
||||
Instruction *MDFrom = nullptr) {
|
||||
const Instruction *MDFrom = nullptr) {
|
||||
SelectInst *Sel =
|
||||
new (AllocMarker) SelectInst(C, S1, S2, NameStr, InsertBefore);
|
||||
if (MDFrom)
|
||||
|
||||
@@ -880,11 +880,13 @@ Instruction *InstCombinerImpl::foldAddWithConstant(BinaryOperator &Add) {
|
||||
// zext(bool) + C -> bool ? C + 1 : C
|
||||
if (match(Op0, m_ZExt(m_Value(X))) &&
|
||||
X->getType()->getScalarSizeInBits() == 1)
|
||||
return createSelectInst(X, InstCombiner::AddOne(Op1C), Op1);
|
||||
return createSelectInstWithUnknownProfile(X, InstCombiner::AddOne(Op1C),
|
||||
Op1);
|
||||
// sext(bool) + C -> bool ? C - 1 : C
|
||||
if (match(Op0, m_SExt(m_Value(X))) &&
|
||||
X->getType()->getScalarSizeInBits() == 1)
|
||||
return createSelectInst(X, InstCombiner::SubOne(Op1C), Op1);
|
||||
return createSelectInstWithUnknownProfile(X, InstCombiner::SubOne(Op1C),
|
||||
Op1);
|
||||
|
||||
// ~X + C --> (C-1) - X
|
||||
if (match(Op0, m_Not(m_Value(X)))) {
|
||||
|
||||
@@ -471,15 +471,16 @@ private:
|
||||
Value *simplifyNonNullOperand(Value *V, bool HasDereferenceable,
|
||||
unsigned Depth = 0);
|
||||
|
||||
SelectInst *createSelectInst(Value *C, Value *S1, Value *S2,
|
||||
const Twine &NameStr = "",
|
||||
InsertPosition InsertBefore = nullptr,
|
||||
Instruction *MDFrom = nullptr) {
|
||||
SelectInst *SI =
|
||||
SelectInst::Create(C, S1, S2, NameStr, InsertBefore, MDFrom);
|
||||
if (!MDFrom)
|
||||
setExplicitlyUnknownBranchWeightsIfProfiled(*SI, F, DEBUG_TYPE);
|
||||
return SI;
|
||||
/// Create `select C, S1, S2`. Use only when the profile cannot be calculated
|
||||
/// from existing profile metadata: if the Function has profiles, this will
|
||||
/// set the profile of this select to "unknown".
|
||||
SelectInst *
|
||||
createSelectInstWithUnknownProfile(Value *C, Value *S1, Value *S2,
|
||||
const Twine &NameStr = "",
|
||||
InsertPosition InsertBefore = nullptr) {
|
||||
auto *Sel = SelectInst::Create(C, S1, S2, NameStr, InsertBefore, nullptr);
|
||||
setExplicitlyUnknownBranchWeightsIfProfiled(*Sel, F, DEBUG_TYPE);
|
||||
return Sel;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
@@ -1253,7 +1253,8 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) {
|
||||
// shl (zext i1 X), C1 --> select (X, 1 << C1, 0)
|
||||
if (match(Op0, m_ZExt(m_Value(X))) && X->getType()->isIntOrIntVectorTy(1)) {
|
||||
auto *NewC = Builder.CreateShl(ConstantInt::get(Ty, 1), C1);
|
||||
return createSelectInst(X, NewC, ConstantInt::getNullValue(Ty));
|
||||
return createSelectInstWithUnknownProfile(X, NewC,
|
||||
ConstantInt::getNullValue(Ty));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1737,7 +1737,7 @@ Instruction *InstCombinerImpl::foldBinopOfSextBoolToSelect(BinaryOperator &BO) {
|
||||
Constant *Zero = ConstantInt::getNullValue(BO.getType());
|
||||
Value *TVal = Builder.CreateBinOp(BO.getOpcode(), Ones, C);
|
||||
Value *FVal = Builder.CreateBinOp(BO.getOpcode(), Zero, C);
|
||||
return createSelectInst(X, TVal, FVal);
|
||||
return createSelectInstWithUnknownProfile(X, TVal, FVal);
|
||||
}
|
||||
|
||||
static Value *simplifyOperationIntoSelectOperand(Instruction &I, SelectInst *SI,
|
||||
|
||||
Reference in New Issue
Block a user