[Mlir-commits] [mlir] [MLIR][GPU] Support bf16 and i1 gpu::shuffles to LLVMSPIRV conversion (PR #119675)

Pietro Ghiglio llvmlistbot at llvm.org
Wed Jan 8 05:40:35 PST 2025


================
@@ -286,33 +287,70 @@ struct GPUShuffleConversion final : ConvertOpToLLVMPattern<gpu::ShuffleOp> {
            val == getSubgroupSize(op);
   }
 
+  static Value bitcastOrExtBeforeShuffle(Value oldVal, Location loc,
+                                         ConversionPatternRewriter &rewriter) {
+    return TypeSwitch<Type, Value>(oldVal.getType())
+        .Case([&](BFloat16Type) {
+          return rewriter.create<LLVM::BitcastOp>(
+              loc, rewriter.getIntegerType(16), oldVal);
+        })
+        .Case([&](IntegerType intTy) -> Value {
+          if (intTy.getWidth() == 1)
+            return rewriter.create<LLVM::ZExtOp>(
+                loc, rewriter.getIntegerType(8), oldVal);
+          return oldVal;
+        })
+        .Default([&](auto) { return oldVal; });
----------------
PietroGhg wrote:

Thanks, I applied your suggestions; `Default(oldVal)` should work because we either fall in a case where we need to bitcast/trunc/ext, or we don't and if we don't we want to use `oldVal`. If `oldVal` is of some unsupported type, we already have checks for it after getting the mangled shuffle builtin, so it looks fine to me

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


More information about the Mlir-commits mailing list