@@ -19679,20 +19679,35 @@ class HorizontalReduction {
19679
19679
return cast<Instruction>(ScalarCond);
19680
19680
};
19681
19681
19682
+ bool AnyBoolLogicOp = any_of(ReductionOps.back(), [](Value *V) {
19683
+ return isBoolLogicOp(cast<Instruction>(V));
19684
+ });
19682
19685
// Return new VectorizedTree, based on previous value.
19683
19686
auto GetNewVectorizedTree = [&](Value *VectorizedTree, Value *Res) {
19684
19687
if (VectorizedTree) {
19685
19688
// Update the final value in the reduction.
19686
19689
Builder.SetCurrentDebugLocation(
19687
19690
cast<Instruction>(ReductionOps.front().front())->getDebugLoc());
19688
- if ((isa<PoisonValue>(VectorizedTree) && !isa<PoisonValue>(Res)) ||
19689
- (isGuaranteedNotToBePoison(Res) &&
19690
- !isGuaranteedNotToBePoison(VectorizedTree))) {
19691
- auto It = ReducedValsToOps.find(Res);
19692
- if (It != ReducedValsToOps.end() &&
19693
- any_of(It->getSecond(),
19694
- [](Instruction *I) { return isBoolLogicOp(I); }))
19691
+ if (AnyBoolLogicOp) {
19692
+
19693
+ if (auto It = ReducedValsToOps.find(VectorizedTree);
19694
+ It == ReducedValsToOps.end() ||
19695
+ isGuaranteedNotToBePoison(VectorizedTree) ||
19696
+ any_of(It->getSecond(), [&](Instruction *I) {
19697
+ return isBoolLogicOp(I) &&
19698
+ getRdxOperand(I, 0) == VectorizedTree;
19699
+ })) {
19700
+ ;
19701
+ } else if (auto It = ReducedValsToOps.find(Res);
19702
+ It == ReducedValsToOps.end() ||
19703
+ isGuaranteedNotToBePoison(Res) ||
19704
+ any_of(It->getSecond(), [&](Instruction *I) {
19705
+ return isBoolLogicOp(I) && getRdxOperand(I, 0) == Res;
19706
+ })) {
19695
19707
std::swap(VectorizedTree, Res);
19708
+ } else {
19709
+ VectorizedTree = Builder.CreateFreeze(VectorizedTree);
19710
+ }
19696
19711
}
19697
19712
19698
19713
return createOp(Builder, RdxKind, VectorizedTree, Res, "op.rdx",
@@ -19701,9 +19716,6 @@ class HorizontalReduction {
19701
19716
// Initialize the final value in the reduction.
19702
19717
return Res;
19703
19718
};
19704
- bool AnyBoolLogicOp = any_of(ReductionOps.back(), [](Value *V) {
19705
- return isBoolLogicOp(cast<Instruction>(V));
19706
- });
19707
19719
SmallDenseSet<Value *> IgnoreList(ReductionOps.size() *
19708
19720
ReductionOps.front().size());
19709
19721
for (ReductionOpsType &RdxOps : ReductionOps)
0 commit comments