[llvm] [LLVM] Add `llvm.masked.compress` intrinsic (PR #92289)

Lawrence Benson via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 12:14:20 PDT 2024


================
@@ -12091,6 +12093,57 @@ SDValue DAGCombiner::visitVP_STRIDED_STORE(SDNode *N) {
   return SDValue();
 }
 
+SDValue DAGCombiner::visitMASKED_COMPRESS(SDNode *N) {
+  SDLoc DL(N);
+  SDValue Vec = N->getOperand(0);
+  SDValue Mask = N->getOperand(1);
+  SDValue Passthru = N->getOperand(2);
+  EVT VecVT = Vec.getValueType();
+
+  bool HasPassthru = !Passthru.isUndef();
+
+  APInt SplatVal;
+  if (ISD::isConstantSplatVector(Mask.getNode(), SplatVal))
+    return SplatVal.isAllOnes()
----------------
lawben wrote:

Good question. Now that you mentioned it, I think we should enforce getBooleanContents, because then we are on the safe side.

As the combiner may run after some initial type legalization, the mask may not be a vector of `i1` anymore. but as it started off as one, some other step must have converted the mask via the appropriate conversion.

Just checking for zero would then also be wrong, because there are configurations in which only bit 0 counts, so any leading garbage != 0 would lead to a wrong result.

i've implemented this logic now. Please check if this is better now.

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


More information about the llvm-commits mailing list