[Mlir-commits] [mlir] [mlir][SPIR-V] Add OpenCL ctz, ilogb, and sincos operations (PR #231713)

Alexander Shaposhnikov llvmlistbot at llvm.org
Tue Oct 13 22:20:13 PDT 2026


================
@@ -292,6 +294,47 @@ struct CountTrailingZerosPattern final
   }
 };
 
+/// Converts math.cttz to OpenCL.std ctz, preserving the source bit width when
+/// narrow integers are emulated using wider integers.
+struct CountTrailingZerosOpenCLPattern final
+    : public OpConversionPattern<math::CountTrailingZerosOp> {
+  using Base::Base;
+
+  LogicalResult
+  matchAndRewrite(math::CountTrailingZerosOp op, OpAdaptor adaptor,
+                  ConversionPatternRewriter &rewriter) const override {
+    if (failed(checkSourceOpTypes(rewriter, op)))
+      return failure();
+
+    auto &typeConverter = *getTypeConverter<SPIRVTypeConverter>();
+    if (!typeConverter.getTargetEnv().allows(spirv::Capability::Kernel))
+      return rewriter.notifyMatchFailure(op, "requires Kernel capability");
+    Type type = typeConverter.convertType(op.getType());
+    if (!type)
+      return failure();
+
+    Type elementType = getElementTypeOrSelf(type);
+    unsigned sourceWidth =
+        getElementTypeOrSelf(op.getType()).getIntOrFloatBitWidth();
----------------
alexander-shaposhnikov wrote:

Fixed

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


More information about the Mlir-commits mailing list