Skip to content

Commit e2d5f62

Browse files
committed
[slp]
1 parent 2a5a05e commit e2d5f62

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

llvm/include/llvm/IR/IRBuilder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2548,6 +2548,11 @@ class IRBuilderBase {
25482548
std::optional<RoundingMode> Rounding = std::nullopt,
25492549
std::optional<fp::ExceptionBehavior> Except = std::nullopt);
25502550

2551+
LLVM_ABI Value *CreateSelectWithUnknownProfile(Value *C, Value *True,
2552+
Value *False,
2553+
StringRef PassName,
2554+
const Twine &Name = "");
2555+
25512556
LLVM_ABI Value *CreateSelect(Value *C, Value *True, Value *False,
25522557
const Twine &Name = "",
25532558
Instruction *MDFrom = nullptr);

llvm/lib/IR/IRBuilder.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/IR/Module.h"
2626
#include "llvm/IR/NoFolder.h"
2727
#include "llvm/IR/Operator.h"
28+
#include "llvm/IR/ProfDataUtils.h"
2829
#include "llvm/IR/Statepoint.h"
2930
#include "llvm/IR/Type.h"
3031
#include "llvm/IR/Value.h"
@@ -1002,6 +1003,18 @@ CallInst *IRBuilderBase::CreateConstrainedFPCall(
10021003
return C;
10031004
}
10041005

1006+
Value *IRBuilderBase::CreateSelectWithUnknownProfile(Value *C, Value *True,
1007+
Value *False,
1008+
StringRef PassName,
1009+
const Twine &Name) {
1010+
Value *Ret = CreateSelectFMF(C, True, False, {}, Name);
1011+
if (auto *SI = dyn_cast<SelectInst>(Ret)) {
1012+
setExplicitlyUnknownBranchWeightsIfProfiled(
1013+
*SI, *SI->getParent()->getParent(), PassName);
1014+
}
1015+
return Ret;
1016+
}
1017+
10051018
Value *IRBuilderBase::CreateSelect(Value *C, Value *True, Value *False,
10061019
const Twine &Name, Instruction *MDFrom) {
10071020
return CreateSelectFMF(C, True, False, {}, Name, MDFrom);

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19414,7 +19414,8 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
1941419414
}
1941519415
assert(getNumElements(Cond->getType()) == TrueNumElements &&
1941619416
"Cannot vectorize Instruction::Select");
19417-
Value *V = Builder.CreateSelect(Cond, True, False);
19417+
Value *V =
19418+
Builder.CreateSelectWithUnknownProfile(Cond, True, False, DEBUG_TYPE);
1941819419
V = FinalShuffle(V, E);
1941919420

1942019421
E->VectorizedValue = V;
@@ -23532,18 +23533,19 @@ class HorizontalReduction {
2353223533
switch (Kind) {
2353323534
case RecurKind::Or: {
2353423535
if (UseSelect && OpTy == CmpInst::makeCmpResultType(OpTy))
23535-
return Builder.CreateSelect(
23536+
return Builder.CreateSelectWithUnknownProfile(
2353623537
LHS, ConstantInt::getAllOnesValue(CmpInst::makeCmpResultType(OpTy)),
23537-
RHS, Name);
23538+
RHS, DEBUG_TYPE, Name);
2353823539
unsigned RdxOpcode = RecurrenceDescriptor::getOpcode(Kind);
2353923540
return Builder.CreateBinOp((Instruction::BinaryOps)RdxOpcode, LHS, RHS,
2354023541
Name);
2354123542
}
2354223543
case RecurKind::And: {
2354323544
if (UseSelect && OpTy == CmpInst::makeCmpResultType(OpTy))
23544-
return Builder.CreateSelect(
23545+
return Builder.CreateSelectWithUnknownProfile(
2354523546
LHS, RHS,
23546-
ConstantInt::getNullValue(CmpInst::makeCmpResultType(OpTy)), Name);
23547+
ConstantInt::getNullValue(CmpInst::makeCmpResultType(OpTy)),
23548+
DEBUG_TYPE, Name);
2354723549
unsigned RdxOpcode = RecurrenceDescriptor::getOpcode(Kind);
2354823550
return Builder.CreateBinOp((Instruction::BinaryOps)RdxOpcode, LHS, RHS,
2354923551
Name);
@@ -23564,7 +23566,8 @@ class HorizontalReduction {
2356423566
if (UseSelect) {
2356523567
CmpInst::Predicate Pred = llvm::getMinMaxReductionPredicate(Kind);
2356623568
Value *Cmp = Builder.CreateICmp(Pred, LHS, RHS, Name);
23567-
return Builder.CreateSelect(Cmp, LHS, RHS, Name);
23569+
return Builder.CreateSelectWithUnknownProfile(Cmp, LHS, RHS, DEBUG_TYPE,
23570+
Name);
2356823571
}
2356923572
[[fallthrough]];
2357023573
case RecurKind::FMax:

0 commit comments

Comments
 (0)