[Mlir-commits] [mlir] [mlir][SPIR-V] Add SPIRVToLLVM conversion for SNegate (PR #206950)
Igor Wodiany
llvmlistbot at llvm.org
Mon Jul 13 01:39:04 PDT 2026
================
@@ -90,17 +90,22 @@ static IntegerAttr minusOneIntegerAttribute(Type type, Builder builder) {
return builder.getIntegerAttr(integerType, -1);
}
+/// Creates `llvm.mlir.constant` with a scalar or vector integer value,
+/// broadcasting `scalarAttr` across the vector if `srcType` is a vector.
+static Value createIntegerConstant(Location loc, Type srcType, Type dstType,
+ PatternRewriter &rewriter,
+ IntegerAttr scalarAttr) {
+ if (auto vecType = dyn_cast<VectorType>(srcType))
+ return LLVM::ConstantOp::create(
+ rewriter, loc, dstType, SplatElementsAttr::get(vecType, scalarAttr));
+ return LLVM::ConstantOp::create(rewriter, loc, dstType, scalarAttr);
+}
+
/// Creates `llvm.mlir.constant` with all bits set for the given type.
static Value createConstantAllBitsSet(Location loc, Type srcType, Type dstType,
PatternRewriter &rewriter) {
- if (isa<VectorType>(srcType)) {
- return LLVM::ConstantOp::create(
- rewriter, loc, dstType,
- SplatElementsAttr::get(cast<ShapedType>(srcType),
- minusOneIntegerAttribute(srcType, rewriter)));
- }
- return LLVM::ConstantOp::create(rewriter, loc, dstType,
- minusOneIntegerAttribute(srcType, rewriter));
+ return createIntegerConstant(loc, srcType, dstType, rewriter,
+ minusOneIntegerAttribute(srcType, rewriter));
----------------
IgWod wrote:
Maybe it'd make sense to inline `minusOneIntegerAttribute` now (unless it's used anywhere else); but that's something for a future cleanup.
https://github.com/llvm/llvm-project/pull/206950
More information about the Mlir-commits
mailing list