[Mlir-commits] [mlir] [mlir][SPIR-V] Convert math.cttz to spirv.GLFindILsb (PR #200455)
Arseniy Obolenskiy
llvmlistbot at llvm.org
Sat May 30 03:01:03 PDT 2026
================
@@ -242,6 +242,45 @@ struct CountLeadingZerosPattern final
}
};
+/// Converts math.cttz to GL FindILsb. GL FindILsb returns -1 for a zero
+/// input while math.cttz must return the bitwidth, so the zero case is
+/// patched up with a select.
+struct CountTrailingZerosPattern final
+ : public OpConversionPattern<math::CountTrailingZerosOp> {
+ using Base::Base;
+
+ LogicalResult
+ matchAndRewrite(math::CountTrailingZerosOp countOp, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ if (LogicalResult res = checkSourceOpTypes(rewriter, countOp); failed(res))
+ return res;
+
+ Type type = getTypeConverter()->convertType(countOp.getType());
+ if (!type)
+ return failure();
+
+ unsigned bitwidth = 0;
+ if (isa<IntegerType>(type))
+ bitwidth = type.getIntOrFloatBitWidth();
+ if (auto vectorType = dyn_cast<VectorType>(type))
----------------
aobolensk wrote:
else if added, thanks
As for f32, `math.cttz` is a `Math_IntegerUnaryOp` (from TableGen definition) so so the op verifier already guarantees an integer or index element type
https://github.com/llvm/llvm-project/pull/200455
More information about the Mlir-commits
mailing list