[Mlir-commits] [mlir] [mlir][SPIR-V] Add SPIRVToLLVM conversion for SNegate (PR #206950)
Igor Wodiany
llvmlistbot at llvm.org
Fri Jul 10 03:05:59 PDT 2026
================
@@ -921,6 +921,35 @@ class InverseSqrtPattern
}
};
+/// Converts `spirv.SNegate` to `0 - x`.
+class SNegatePattern : public SPIRVToLLVMConversion<spirv::SNegateOp> {
+public:
+ using SPIRVToLLVMConversion<spirv::SNegateOp>::SPIRVToLLVMConversion;
+
+ LogicalResult
+ matchAndRewrite(spirv::SNegateOp op, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ auto srcType = op.getType();
+ auto dstType = getTypeConverter()->convertType(srcType);
+ if (!dstType)
+ return rewriter.notifyMatchFailure(op, "type conversion failed");
+
+ Location loc = op.getLoc();
+ auto vecSrcType = dyn_cast<VectorType>(srcType);
+ IntegerAttr zeroAttr = rewriter.getIntegerAttr(
+ cast<IntegerType>(getElementTypeOrSelf(srcType)), 0);
+ Value zero;
+ if (vecSrcType)
+ zero = LLVM::ConstantOp::create(
+ rewriter, loc, dstType, SplatElementsAttr::get(vecSrcType, zeroAttr));
+ else
+ zero = LLVM::ConstantOp::create(rewriter, loc, dstType, zeroAttr);
----------------
IgWod wrote:
Would it make sense to generalise `createConstantAllBitsSet` and use it here?
https://github.com/llvm/llvm-project/pull/206950
More information about the Mlir-commits
mailing list