[llvm] [ValueTracking][X86] Compute KnownBits for phadd/phsub (PR #92429)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 09:43:21 PDT 2024


================
@@ -950,6 +950,36 @@ 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, KnownBitsFunc](const Value *Op, APInt &DemandedEltsOp) {
+        std::array<KnownBits, 2> Known;
+        for (unsigned Index = 0; Index < Known.size(); ++Index) {
+          Known[Index] = computeKnownBits(Op, DemandedEltsOp, Depth + 1, Q);
+          DemandedEltsOp <<= 1;
+        }
+        return KnownBitsFunc(Known[0], Known[1]);
----------------
goldsteinn wrote:

Truthfully a loop + temp array is for complication thats it worth here.

`return KnownBitsFunc(computeKnownBits(Op, DemandedEltsOp, Depth + 1, Q), computeKnownBits(Op, DemandedEltsOp << 1, Depth + 1, Q));`

https://github.com/llvm/llvm-project/pull/92429


More information about the llvm-commits mailing list