[clang-tools-extra] [libcxx] [mlir] [clang] [llvm] [flang] [LV] Improve AnyOf reduction codegen. (PR #78304)
Florian Hahn via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 5 06:29:38 PST 2024
================
@@ -1079,16 +1070,13 @@ Value *llvm::createAnyOfTargetReduction(IRBuilderBase &Builder, Value *Src,
NewVal = SI->getTrueValue();
}
- // Create a splat vector with the new value and compare this to the vector
- // we want to reduce.
- ElementCount EC = cast<VectorType>(Src->getType())->getElementCount();
- Value *Right = Builder.CreateVectorSplat(EC, InitVal);
- Value *Cmp =
- Builder.CreateCmp(CmpInst::ICMP_NE, Src, Right, "rdx.select.cmp");
-
// If any predicate is true it means that we want to select the new value.
- Cmp = Builder.CreateOrReduce(Cmp);
- return Builder.CreateSelect(Cmp, NewVal, InitVal, "rdx.select");
+ Value *AnyOf =
+ Src->getType()->isVectorTy() ? Builder.CreateOrReduce(Src) : Src;
+ // The compares in the loop may yield poison, which propagates through the
+ // bitwise ORs. Freeze it here before the condition is used.
+ AnyOf = Builder.CreateFreeze(AnyOf);
----------------
fhahn wrote:
> Similar to a plain "result |= value[i]" OR reduction,
Freeze won't be needed in that case; if there's already a binary OR in the input, poison from the compare gets already propagated. It is only needed when converting from the `select` form (which doesn't propagate poison from the condition to its result)
Yes, but this will need a bit of additional refactoring, in particular how `createAndCollectMergePhiForReduction` looks up the reduction result value and when `ComputeReductionResult` VPInstructions are created.
https://github.com/llvm/llvm-project/pull/78304
More information about the cfe-commits
mailing list