[llvm] [ValueTracking][X86] Compute KnownBits for phadd/phsub (PR #92429)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 4 10:53:23 PDT 2024
================
@@ -950,6 +950,39 @@ getKnownBitsFromAndXorOr(const Operator *I, const APInt &DemandedElts,
return KnownOut;
}
+static KnownBits computeKnownBitsForHorizontalOperation(
+ const Operator *I, const APInt &DemandedElts, unsigned Depth,
+ const SimplifyQuery &Q,
+ const function_ref<KnownBits(const KnownBits &, const KnownBits &)>
+ KnownBitsFunc) {
+ APInt DemandedEltsLHS, DemandedEltsRHS;
+ getHorizDemandedEltsForFirstOperand(Q.DL.getTypeSizeInBits(I->getType()),
+ DemandedElts, DemandedEltsLHS,
+ DemandedEltsRHS);
+
+ const auto ComputeForSingleOpFunc =
+ [Depth, &Q](const Value *Op, APInt &DemandedEltsOp,
+ std::array<KnownBits, 2> &Known) {
+ for (unsigned Index = 0; Index < Known.size(); ++Index) {
+ if (!DemandedEltsOp.isZero()) {
+ Known[Index] = computeKnownBits(Op, DemandedEltsOp, Depth + 1, Q);
+ } else {
+ Known[Index] = KnownBits(getBitWidth(Op->getType(), Q.DL));
+ Known[Index].setAllZero();
----------------
goldsteinn wrote:
I think this works but it is not at all clear.
AFAICT only `Index == 1` can be skipped, so zero does serve as an identity for all KnownBitsFunc you seem to pass. But this seems aggressively error prone.
I would say at the very least since you accept arbitrary `KnownBitsFunc` for reducing, you should also being taking a function that sets the identity. You can have an overload with the current code here.
Think would also like an assert that Index == 1 here for clarities sake.
Truthfully I might just drop demanded entirely.
https://github.com/llvm/llvm-project/pull/92429
More information about the llvm-commits
mailing list