@@ -1001,8 +1001,9 @@ class BoUpSLP {
1001
1001
TargetLibraryInfo *TLi, AAResults *Aa, LoopInfo *Li,
1002
1002
DominatorTree *Dt, AssumptionCache *AC, DemandedBits *DB,
1003
1003
const DataLayout *DL, OptimizationRemarkEmitter *ORE)
1004
- : BatchAA(*Aa), F(Func), SE(Se), TTI(Tti), TLI(TLi), LI(Li),
1005
- DT(Dt), AC(AC), DB(DB), DL(DL), ORE(ORE), Builder(Se->getContext()) {
1004
+ : BatchAA(*Aa), F(Func), SE(Se), TTI(Tti), TLI(TLi), LI(Li), DT(Dt),
1005
+ AC(AC), DB(DB), DL(DL), ORE(ORE),
1006
+ Builder(Se->getContext(), TargetFolder(*DL)) {
1006
1007
CodeMetrics::collectEphemeralValues(F, AC, EphValues);
1007
1008
// Use the vector register size specified by the target unless overridden
1008
1009
// by a command-line option.
@@ -3642,7 +3643,7 @@ class BoUpSLP {
3642
3643
unsigned MinVecRegSize; // Set by cl::opt (default: 128).
3643
3644
3644
3645
/// Instruction builder to construct the vectorized tree.
3645
- IRBuilder<> Builder;
3646
+ IRBuilder<TargetFolder > Builder;
3646
3647
3647
3648
/// A map of scalar integer values to the smallest bit width with which they
3648
3649
/// can legally be represented. The values map to (width, signed) pairs,
@@ -15031,7 +15032,6 @@ class HorizontalReduction {
15031
15032
static Value *createOp(IRBuilderBase &Builder, RecurKind Kind, Value *LHS,
15032
15033
Value *RHS, const Twine &Name, bool UseSelect) {
15033
15034
unsigned RdxOpcode = RecurrenceDescriptor::getOpcode(Kind);
15034
- bool IsConstant = isConstant(LHS) && isConstant(RHS);
15035
15035
switch (Kind) {
15036
15036
case RecurKind::Or:
15037
15037
if (UseSelect &&
@@ -15053,49 +15053,33 @@ class HorizontalReduction {
15053
15053
return Builder.CreateBinOp((Instruction::BinaryOps)RdxOpcode, LHS, RHS,
15054
15054
Name);
15055
15055
case RecurKind::FMax:
15056
- if (IsConstant)
15057
- return ConstantFP::get(LHS->getType(),
15058
- maxnum(cast<ConstantFP>(LHS)->getValueAPF(),
15059
- cast<ConstantFP>(RHS)->getValueAPF()));
15060
15056
return Builder.CreateBinaryIntrinsic(Intrinsic::maxnum, LHS, RHS);
15061
15057
case RecurKind::FMin:
15062
- if (IsConstant)
15063
- return ConstantFP::get(LHS->getType(),
15064
- minnum(cast<ConstantFP>(LHS)->getValueAPF(),
15065
- cast<ConstantFP>(RHS)->getValueAPF()));
15066
15058
return Builder.CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS);
15067
15059
case RecurKind::FMaximum:
15068
- if (IsConstant)
15069
- return ConstantFP::get(LHS->getType(),
15070
- maximum(cast<ConstantFP>(LHS)->getValueAPF(),
15071
- cast<ConstantFP>(RHS)->getValueAPF()));
15072
15060
return Builder.CreateBinaryIntrinsic(Intrinsic::maximum, LHS, RHS);
15073
15061
case RecurKind::FMinimum:
15074
- if (IsConstant)
15075
- return ConstantFP::get(LHS->getType(),
15076
- minimum(cast<ConstantFP>(LHS)->getValueAPF(),
15077
- cast<ConstantFP>(RHS)->getValueAPF()));
15078
15062
return Builder.CreateBinaryIntrinsic(Intrinsic::minimum, LHS, RHS);
15079
15063
case RecurKind::SMax:
15080
- if (IsConstant || UseSelect) {
15064
+ if (UseSelect) {
15081
15065
Value *Cmp = Builder.CreateICmpSGT(LHS, RHS, Name);
15082
15066
return Builder.CreateSelect(Cmp, LHS, RHS, Name);
15083
15067
}
15084
15068
return Builder.CreateBinaryIntrinsic(Intrinsic::smax, LHS, RHS);
15085
15069
case RecurKind::SMin:
15086
- if (IsConstant || UseSelect) {
15070
+ if (UseSelect) {
15087
15071
Value *Cmp = Builder.CreateICmpSLT(LHS, RHS, Name);
15088
15072
return Builder.CreateSelect(Cmp, LHS, RHS, Name);
15089
15073
}
15090
15074
return Builder.CreateBinaryIntrinsic(Intrinsic::smin, LHS, RHS);
15091
15075
case RecurKind::UMax:
15092
- if (IsConstant || UseSelect) {
15076
+ if (UseSelect) {
15093
15077
Value *Cmp = Builder.CreateICmpUGT(LHS, RHS, Name);
15094
15078
return Builder.CreateSelect(Cmp, LHS, RHS, Name);
15095
15079
}
15096
15080
return Builder.CreateBinaryIntrinsic(Intrinsic::umax, LHS, RHS);
15097
15081
case RecurKind::UMin:
15098
- if (IsConstant || UseSelect) {
15082
+ if (UseSelect) {
15099
15083
Value *Cmp = Builder.CreateICmpULT(LHS, RHS, Name);
15100
15084
return Builder.CreateSelect(Cmp, LHS, RHS, Name);
15101
15085
}
@@ -15489,7 +15473,7 @@ class HorizontalReduction {
15489
15473
}
15490
15474
15491
15475
/// Attempt to vectorize the tree found by matchAssociativeReduction.
15492
- Value *tryToReduce(BoUpSLP &V, TargetTransformInfo *TTI,
15476
+ Value *tryToReduce(BoUpSLP &V, const DataLayout &DL, TargetTransformInfo *TTI,
15493
15477
const TargetLibraryInfo &TLI) {
15494
15478
constexpr int ReductionLimit = 4;
15495
15479
constexpr unsigned RegMaxNumber = 4;
@@ -15515,7 +15499,9 @@ class HorizontalReduction {
15515
15499
return nullptr;
15516
15500
}
15517
15501
15518
- IRBuilder<> Builder(cast<Instruction>(ReductionRoot));
15502
+ IRBuilder<TargetFolder> Builder(ReductionRoot->getContext(),
15503
+ TargetFolder(DL));
15504
+ Builder.SetInsertPoint(cast<Instruction>(ReductionRoot));
15519
15505
15520
15506
// Track the reduced values in case if they are replaced by extractelement
15521
15507
// because of the vectorization.
@@ -16611,7 +16597,7 @@ bool SLPVectorizerPass::vectorizeHorReduction(
16611
16597
HorizontalReduction HorRdx;
16612
16598
if (!HorRdx.matchAssociativeReduction(R, Inst, *SE, *DL, *TLI))
16613
16599
return nullptr;
16614
- return HorRdx.tryToReduce(R, TTI, *TLI);
16600
+ return HorRdx.tryToReduce(R, *DL, TTI, *TLI);
16615
16601
};
16616
16602
auto TryAppendToPostponedInsts = [&](Instruction *FutureSeed) {
16617
16603
if (TryOperandsAsNewSeeds && FutureSeed == Root) {
0 commit comments