[llvm] [IA][RISCV] Detecting gap mask from a mask assembled by interleaveN intrinsics (PR #153510)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 13 22:22:39 PDT 2025


================
@@ -596,7 +596,26 @@ static std::pair<Value *, APInt> getMask(Value *WideMask, unsigned Factor,
 
   if (auto *IMI = dyn_cast<IntrinsicInst>(WideMask)) {
     if (unsigned F = getInterleaveIntrinsicFactor(IMI->getIntrinsicID());
-        F && F == Factor && llvm::all_equal(IMI->args())) {
+        F && F == Factor) {
+      Value *RefArg = nullptr;
+      // Check if all the intrinsic arguments are the same, except those that
+      // are zeros, which we mark them as gaps in the gap mask.
+      for (auto [Idx, Arg] : enumerate(IMI->args())) {
+        if (auto *C = dyn_cast<Constant>(Arg); C && C->isZeroValue()) {
+          GapMask.clearBit(Idx);
+          continue;
+        }
+
+        if (!RefArg)
+          RefArg = Arg;
+
+        if (RefArg != Arg)
+          return {nullptr, GapMask};
----------------
lukel97 wrote:

Nit, this can be an else if?
```suggestion
        if (!RefArg)
          RefArg = Arg;
        else if (RefArg != Arg)
          return {nullptr, GapMask};
```

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


More information about the llvm-commits mailing list