[llvm] [ValueTracking][X86] Compute KnownBits for phadd/phsub (PR #92429)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 2 09:53:54 PDT 2024
================
@@ -950,6 +950,43 @@ 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);
+
+ std::array<KnownBits, 2> KnownLHS;
+ for (unsigned Index = 0; Index < KnownLHS.size(); ++Index) {
+ if (!DemandedEltsLHS.isZero()) {
+ KnownLHS[Index] =
+ computeKnownBits(I->getOperand(0), DemandedEltsLHS, Depth + 1, Q);
+ } else {
+ KnownLHS[Index] = KnownBits(I->getType()->getScalarSizeInBits());
+ KnownLHS[Index].setAllZero();
+ }
+ DemandedEltsLHS <<= 1;
+ }
+ std::array<KnownBits, 2> KnownRHS;
+ for (unsigned Index = 0; Index < KnownRHS.size(); ++Index) {
+ if (!DemandedEltsRHS.isZero()) {
+ KnownRHS[Index] =
+ computeKnownBits(I->getOperand(1), DemandedEltsRHS, Depth + 1, Q);
+ } else {
+ KnownRHS[Index] = KnownBits(I->getType()->getScalarSizeInBits());
+ KnownRHS[Index].setAllZero();
+ }
+ DemandedEltsRHS <<= 1;
+ }
----------------
goldsteinn wrote:
The LHS and RHS code is complete dup. Can you create a lambda to handle it?
https://github.com/llvm/llvm-project/pull/92429
More information about the llvm-commits
mailing list