[llvm] [ValueTracking] Add support for `llvm.vector.reduce.{xor,or,and}` ops. (PR #88320)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 12 17:40:34 PDT 2024


================
@@ -1624,14 +1624,29 @@ static void computeKnownBitsFromOperator(const Operator *I,
         computeKnownBits(I->getOperand(1), Known2, Depth + 1, Q);
         Known = KnownBits::ssub_sat(Known, Known2);
         break;
-        // for min/max reduce, any bit common to each element in the input vec
-        // is set in the output.
+        // for min/max/and/or reduce, any bit common to each element in the
+        // input vec is set in the output.
+      case Intrinsic::vector_reduce_and:
+      case Intrinsic::vector_reduce_or:
       case Intrinsic::vector_reduce_umax:
       case Intrinsic::vector_reduce_umin:
       case Intrinsic::vector_reduce_smax:
       case Intrinsic::vector_reduce_smin:
         computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
         break;
+      case Intrinsic::vector_reduce_xor: {
+        computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
+        // The zeros common to all vecs are zero in the output.
+        // If the number of elements is odd, then the common ones remain. If the
+        // number of elements is even, then the common ones becomes zeros.
+        auto *VecTy = cast<VectorType>(I->getOperand(0)->getType());
+        // Even, so the ones become zeros.
+        if (VecTy->getElementCount().isKnownEven()) {
----------------
nikic wrote:

Shouldn't this have an else that sets the ones to unknown? Otherwise what about something like `vscale x 3` which is not known even but might be.

(Actually, I'd just condition the whole xor code on isKnownEven, we don't care about odd-size vectors anyway.)

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


More information about the llvm-commits mailing list