[llvm] [AMDGPU] Teach CalculateByteProvider about AMDGPUISD::PERM (PR #65547)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 7 09:36:17 PDT 2023


================
@@ -10762,6 +10762,24 @@ calculateByteProvider(const SDValue &Op, unsigned Index, unsigned Depth,
                             StartingIndex, Index);
   }
 
+  case AMDGPUISD::PERM: {
+    auto PermMask = dyn_cast<ConstantSDNode>(Op->getOperand(2));
+    if (!PermMask)
+      return std::nullopt;
+
+    auto IdxMask =
+        (PermMask->getZExtValue() & (0xFF << (Index * 8))) >> (Index * 8);
+    if (IdxMask > 0x07 && IdxMask != 0x0c)
+      return std::nullopt;
+
+    auto NextOp = IdxMask > 0x03 ? Op.getOperand(0) : Op.getOperand(1);
+    auto NextIndex = IdxMask > 0x03 ? IdxMask % 4 : IdxMask;
+
+    return IdxMask != 0x0c ? calculateSrcByte(NextOp, StartingIndex, NextIndex)
+                           : std::optional<ByteProvider<SDValue>>(
----------------
arsenm wrote:

Do you need the explicit std::optional here?

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


More information about the llvm-commits mailing list