Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/IR/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ class SelectInst : public Instruction {
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)
Expand Down
6 changes: 4 additions & 2 deletions llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))) {
Expand Down
19 changes: 10 additions & 9 deletions llvm/lib/Transforms/InstCombine/InstCombineInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,16 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
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:
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down