[Mlir-commits] [flang] [llvm] [mlir] [do not merge] Remove offset from the memref type and treat it as always dynamic. (PR #192644)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Apr 17 05:41:27 PDT 2026


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions h,cpp,c -- flang/include/flang/Optimizer/Transforms/FIRToMemRefTypeConverter.h flang/lib/Optimizer/CodeGen/CodeGen.cpp flang/lib/Optimizer/Transforms/FIRToMemRef.cpp mlir/include/mlir-c/BuiltinAttributes.h mlir/include/mlir-c/BuiltinTypes.h mlir/include/mlir/Dialect/MemRef/Transforms/Transforms.h mlir/include/mlir/IR/BuiltinAttributeInterfaces.h mlir/lib/Analysis/DataFlow/StridedMetadataRangeAnalysis.cpp mlir/lib/AsmParser/AttributeParser.cpp mlir/lib/Bindings/Python/IRAttributes.cpp mlir/lib/Bindings/Python/IRTypes.cpp mlir/lib/CAPI/IR/BuiltinAttributes.cpp mlir/lib/CAPI/IR/BuiltinTypes.cpp mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp mlir/lib/Conversion/LLVMCommon/Pattern.cpp mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp mlir/lib/Conversion/LinalgToStandard/LinalgToStandard.cpp mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp mlir/lib/Conversion/PtrToLLVM/PtrToLLVM.cpp mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp mlir/lib/Conversion/VectorToXeGPU/VectorToXeGPU.cpp mlir/lib/Conversion/XeGPUToXeVM/XeGPUToXeVM.cpp mlir/lib/Dialect/AMDGPU/IR/AMDGPUOps.cpp mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp mlir/lib/Dialect/Bufferization/Transforms/BufferResultsToOutParams.cpp mlir/lib/Dialect/GPU/Transforms/DecomposeMemRefs.cpp mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp mlir/lib/Dialect/MemRef/Transforms/ElideReinterpretCast.cpp mlir/lib/Dialect/MemRef/Transforms/EmulateNarrowType.cpp mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp mlir/lib/Dialect/MemRef/Transforms/ExtractAddressComputations.cpp mlir/lib/Dialect/MemRef/Transforms/FlattenMemRefs.cpp mlir/lib/Dialect/MemRef/Transforms/IndependenceTransforms.cpp mlir/lib/Dialect/MemRef/Transforms/RuntimeOpVerification.cpp mlir/lib/Dialect/MemRef/Utils/MemRefUtils.cpp mlir/lib/Dialect/NVGPU/Utils/MMAUtils.cpp mlir/lib/Dialect/SCF/Transforms/ParallelLoopFusion.cpp mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp mlir/lib/Dialect/X86/IR/X86Dialect.cpp mlir/lib/Dialect/XeGPU/IR/XeGPUOps.cpp mlir/lib/IR/BuiltinAttributeInterfaces.cpp mlir/lib/IR/BuiltinAttributes.cpp mlir/lib/IR/BuiltinTypes.cpp mlir/test/CAPI/ir.c mlir/test/lib/Analysis/TestMemRefStrideCalculation.cpp mlir/unittests/Dialect/MemRef/InferShapeTest.cpp mlir/unittests/IR/MemrefLayoutTest.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/mlir/include/mlir-c/BuiltinAttributes.h b/mlir/include/mlir-c/BuiltinAttributes.h
index 74c7730fc..3de3a69c1 100644
--- a/mlir/include/mlir-c/BuiltinAttributes.h
+++ b/mlir/include/mlir-c/BuiltinAttributes.h
@@ -747,9 +747,8 @@ MLIR_CAPI_EXPORTED MlirTypeID mlirSparseElementsAttrGetTypeID(void);
 MLIR_CAPI_EXPORTED bool mlirAttributeIsAStridedLayout(MlirAttribute attr);
 
 // Creates a strided layout attribute from the given strides.
-MLIR_CAPI_EXPORTED MlirAttribute
-mlirStridedLayoutAttrGet(MlirContext ctx, intptr_t numStrides,
-                         const int64_t *strides);
+MLIR_CAPI_EXPORTED MlirAttribute mlirStridedLayoutAttrGet(
+    MlirContext ctx, intptr_t numStrides, const int64_t *strides);
 
 MLIR_CAPI_EXPORTED MlirStringRef mlirStridedLayoutAttrGetName(void);
 
diff --git a/mlir/include/mlir-c/BuiltinTypes.h b/mlir/include/mlir-c/BuiltinTypes.h
index b86b61a82..c2a830207 100644
--- a/mlir/include/mlir-c/BuiltinTypes.h
+++ b/mlir/include/mlir-c/BuiltinTypes.h
@@ -538,8 +538,8 @@ MLIR_CAPI_EXPORTED MlirAttribute mlirMemRefTypeGetMemorySpace(MlirType type);
 /// Returns the strides of the MemRef if the layout map is in strided form.
 /// strides is an out param and must point to pre-allocated memory of length
 /// equal to the rank of the memref.
-MLIR_CAPI_EXPORTED MlirLogicalResult
-mlirMemRefTypeGetStrides(MlirType type, int64_t *strides);
+MLIR_CAPI_EXPORTED MlirLogicalResult mlirMemRefTypeGetStrides(MlirType type,
+                                                              int64_t *strides);
 
 /// Returns the memory spcae of the given Unranked MemRef type.
 MLIR_CAPI_EXPORTED MlirAttribute
diff --git a/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp b/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp
index 9a904c898..b11eab27f 100644
--- a/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp
+++ b/mlir/lib/Conversion/AMDGPUToROCDL/AMDGPUToROCDL.cpp
@@ -241,8 +241,7 @@ struct FatRawBufferCastLowering
       // top by the buffer rsrc, so num_records must cover that extra range.
       if (!adaptor.getResetOffset()) {
         Value descOffset = descriptor.offset(rewriter, loc);
-        Value descOffsetI64 =
-            convertUnsignedToI64(rewriter, loc, descOffset);
+        Value descOffsetI64 = convertUnsignedToI64(rewriter, loc, descOffset);
         Value byteWidthConst =
             createI64Constant(rewriter, loc, elementByteWidth);
         Value descOffsetBytes =
diff --git a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
index aeb0c37bb..02125627b 100644
--- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
@@ -769,8 +769,8 @@ SmallVector<Value, 4> LLVMTypeConverter::promoteOperands(
       if (auto memrefType = dyn_cast<MemRefType>(operand.getType())) {
         assert(llvmOperand.size() == 1 && "Expected a single operand");
         MemRefDescriptor desc(llvmOperand.front());
-        promotedOperands.push_back(desc.bufferPtr(builder, loc, *this,
-                                                  memrefType));
+        promotedOperands.push_back(
+            desc.bufferPtr(builder, loc, *this, memrefType));
         continue;
       }
       if (isa<UnrankedMemRefType>(operand.getType())) {
diff --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
index 8ceebf103..f1fb79a06 100644
--- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
+++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
@@ -1514,8 +1514,8 @@ private:
       // Extract the strides from the type.
       SmallVector<int64_t> strides;
       if (failed(targetMemRefType.getStrides(strides)))
-        return rewriter.notifyMatchFailure(
-            reshapeOp, "failed to get stride exprs");
+        return rewriter.notifyMatchFailure(reshapeOp,
+                                           "failed to get stride exprs");
 
       desc.setConstantOffset(rewriter, loc, 0);
 
@@ -1615,8 +1615,8 @@ private:
         rewriter, loc, *getTypeConverter(), targetSizesBase, resultRank);
     // Use bufferPtr so the shape memref's runtime offset is folded in;
     // otherwise the indexed loads below would read at the wrong address.
-    Value shapeOperandPtr =
-        shapeDesc.bufferPtr(rewriter, loc, *getTypeConverter(), shapeMemRefType);
+    Value shapeOperandPtr = shapeDesc.bufferPtr(
+        rewriter, loc, *getTypeConverter(), shapeMemRefType);
     Value oneIndex = createIndexAttrConstant(rewriter, loc, getIndexType(), 1);
     Value resultRankMinusOne =
         LLVM::SubOp::create(rewriter, loc, resultRank, oneIndex);
@@ -1847,8 +1847,8 @@ struct ViewOpLowering : public ConvertOpToLLVMPattern<memref::ViewOp> {
     // Field 2: Compute the target aligned pointer. Start from the source's
     // runtime buffer pointer (aligned ptr + source offset) so any non-zero
     // source offset is preserved, then apply the byteShift.
-    Value alignedPtr = sourceMemRef.bufferPtr(rewriter, loc, *getTypeConverter(),
-                                              srcMemRefType);
+    Value alignedPtr = sourceMemRef.bufferPtr(
+        rewriter, loc, *getTypeConverter(), srcMemRefType);
     alignedPtr = LLVM::GEPOp::create(
         rewriter, loc, alignedPtr.getType(),
         typeConverter->convertType(srcMemRefType.getElementType()), alignedPtr,
@@ -1860,8 +1860,8 @@ struct ViewOpLowering : public ConvertOpToLLVMPattern<memref::ViewOp> {
     // Field 3: The offset in the resulting type must be 0. This is
     // because of the type change: an offset on srcType* may not be
     // expressible as an offset on dstType*.
-    targetMemRef.setOffset(rewriter, loc,
-                           createIndexAttrConstant(rewriter, loc, indexType, 0));
+    targetMemRef.setOffset(
+        rewriter, loc, createIndexAttrConstant(rewriter, loc, indexType, 0));
 
     // Early exit for 0-D corner case.
     if (viewMemRefType.getRank() == 0)
diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
index 602f85187..1e5581ae8 100644
--- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
+++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
@@ -746,8 +746,7 @@ bool CastOp::areCastCompatible(TypeRange inputs, TypeRange outputs) {
       return false;
     if (aT.getLayout() != bT.getLayout()) {
       SmallVector<int64_t, 4> aStrides, bStrides;
-      if (failed(aT.getStrides(aStrides)) ||
-          failed(bT.getStrides(bStrides)) ||
+      if (failed(aT.getStrides(aStrides)) || failed(bT.getStrides(bStrides)) ||
           aStrides.size() != bStrides.size())
         return false;
 
@@ -2032,8 +2031,7 @@ void ReinterpretCastOp::build(OpBuilder &b, OperationState &result,
   dispatchIndexOpFoldResults(offset, dynamicOffsets, staticOffsets);
   dispatchIndexOpFoldResults(sizes, dynamicSizes, staticSizes);
   dispatchIndexOpFoldResults(strides, dynamicStrides, staticStrides);
-  auto stridedLayout =
-      StridedLayoutAttr::get(b.getContext(), staticStrides);
+  auto stridedLayout = StridedLayoutAttr::get(b.getContext(), staticStrides);
   auto resultType = MemRefType::get(staticSizes, sourceType.getElementType(),
                                     stridedLayout, sourceType.getMemorySpace());
   build(b, result, resultType, source, offset, sizes, strides, attrs);
@@ -3140,10 +3138,10 @@ MemRefType SubViewOp::inferRankReducedResultType(
     if (!dimsToProject->contains(idx))
       rankReducedStrides.push_back(value);
   }
-  return MemRefType::get(resultShape, inferredType.getElementType(),
-                         StridedLayoutAttr::get(inferredLayout.getContext(),
-                                                rankReducedStrides),
-                         inferredType.getMemorySpace());
+  return MemRefType::get(
+      resultShape, inferredType.getElementType(),
+      StridedLayoutAttr::get(inferredLayout.getContext(), rankReducedStrides),
+      inferredType.getMemorySpace());
 }
 
 MemRefType SubViewOp::inferRankReducedResultType(
diff --git a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
index 58339e80a..c9eaca061 100644
--- a/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
+++ b/mlir/lib/Dialect/SPIRV/Transforms/SPIRVConversion.cpp
@@ -209,8 +209,7 @@ getTypeNumBytes(const SPIRVConversionOptions &options, Type type) {
     // using the layout from MemRef. Offset is no longer carried by the type;
     // the runtime offset is treated as 0 for sizing purposes here.
     SmallVector<int64_t, 4> strides;
-    if (!memRefType.hasStaticShape() ||
-        failed(memRefType.getStrides(strides)))
+    if (!memRefType.hasStaticShape() || failed(memRefType.getStrides(strides)))
       return std::nullopt;
 
     // To get the size of the memref object in memory, the total size is the
@@ -1380,8 +1379,8 @@ Value mlir::spirv::getVulkanElementPtr(const SPIRVTypeConverter &typeConverter,
   if (baseType.getRank() == 0) {
     linearizedIndices.push_back(zero);
   } else {
-    linearizedIndices.push_back(
-        linearizeIndex(indices, strides, /*offset=*/0, indexType, loc, builder));
+    linearizedIndices.push_back(linearizeIndex(indices, strides, /*offset=*/0,
+                                               indexType, loc, builder));
   }
   return spirv::AccessChainOp::create(builder, loc, basePtr, linearizedIndices);
 }
diff --git a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
index 978b9ffb8..322666a6a 100644
--- a/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
+++ b/mlir/lib/Dialect/SparseTensor/IR/SparseTensorDialect.cpp
@@ -1626,10 +1626,9 @@ static LogicalResult inferSparseBufferType(ValueRange ops, DictionaryAttr attr,
   SmallVector<int64_t> bufShape = stt.getBatchLvlShape();
   bufShape.push_back(ShapedType::kDynamic);
 
-  auto layout = withStride
-                    ? StridedLayoutAttr::get(stt.getContext(),
-                                             {ShapedType::kDynamic})
-                    : StridedLayoutAttr();
+  auto layout = withStride ? StridedLayoutAttr::get(stt.getContext(),
+                                                    {ShapedType::kDynamic})
+                           : StridedLayoutAttr();
   ret.emplace_back(MemRefType::get(bufShape, elemTp, layout));
   return success();
 }
diff --git a/mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp b/mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
index a44cb6c7e..da65fdd61 100644
--- a/mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
+++ b/mlir/lib/Dialect/Tensor/Transforms/BufferizableOpInterfaceImpl.cpp
@@ -194,10 +194,10 @@ struct CollapseShapeOpInterface
         SmallVector<int64_t> strides;
         if (failed(bufferType.getStrides(strides)))
           return failure();
-        resultType = MemRefType::get(
-            {}, tensorResultType.getElementType(),
-            StridedLayoutAttr::get(op->getContext(), {}),
-            bufferType.getMemorySpace());
+        resultType =
+            MemRefType::get({}, tensorResultType.getElementType(),
+                            StridedLayoutAttr::get(op->getContext(), {}),
+                            bufferType.getMemorySpace());
       }
 
       replaceOpWithNewBufferizedOp<memref::CollapseShapeOp>(
diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp
index 2811618b1..7faffefc1 100644
--- a/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/VectorTransferSplitRewritePatterns.cpp
@@ -152,9 +152,8 @@ static MemRefType getCastCompatibleMemRefType(MemRefType aT, MemRefType bT) {
     resStrides[idx] =
         (aStrides[idx] == bStrides[idx]) ? aStrides[idx] : ShapedType::kDynamic;
   }
-  return MemRefType::get(
-      resShape, aT.getElementType(),
-      StridedLayoutAttr::get(aT.getContext(), resStrides));
+  return MemRefType::get(resShape, aT.getElementType(),
+                         StridedLayoutAttr::get(aT.getContext(), resStrides));
 }
 
 /// Casts the given memref to a compatible memref type. If the source memref has
diff --git a/mlir/unittests/Dialect/MemRef/InferShapeTest.cpp b/mlir/unittests/Dialect/MemRef/InferShapeTest.cpp
index 6810e0d11..4c4d582a9 100644
--- a/mlir/unittests/Dialect/MemRef/InferShapeTest.cpp
+++ b/mlir/unittests/Dialect/MemRef/InferShapeTest.cpp
@@ -23,8 +23,7 @@ TEST(InferShapeTest, inferRankReducedShapeIdentity) {
   auto reducedType = SubViewOp::inferRankReducedResultType(
       /*resultShape=*/{2}, sourceMemref, {2, 3}, {1, 2}, {1, 1});
   auto expectedType = MemRefType::get(
-      {2}, b.getIndexType(),
-      StridedLayoutAttr::get(&ctx, /*strides=*/{1}));
+      {2}, b.getIndexType(), StridedLayoutAttr::get(&ctx, /*strides=*/{1}));
   EXPECT_EQ(reducedType, expectedType);
 }
 
@@ -39,8 +38,7 @@ TEST(InferShapeTest, inferRankReducedShapeNonIdentity) {
   auto reducedType = SubViewOp::inferRankReducedResultType(
       /*resultShape=*/{2}, sourceMemref, {2, 3}, {1, 2}, {1, 1});
   auto expectedType = MemRefType::get(
-      {2}, b.getIndexType(),
-      StridedLayoutAttr::get(&ctx, /*strides=*/{1}));
+      {2}, b.getIndexType(), StridedLayoutAttr::get(&ctx, /*strides=*/{1}));
   EXPECT_EQ(reducedType, expectedType);
 }
 
@@ -54,7 +52,6 @@ TEST(InferShapeTest, inferRankReducedShapeToScalar) {
   auto reducedType = SubViewOp::inferRankReducedResultType(
       /*resultShape=*/{}, sourceMemref, {2, 3}, {1, 1}, {1, 1});
   auto expectedType = MemRefType::get(
-      {}, b.getIndexType(),
-      StridedLayoutAttr::get(&ctx, /*strides=*/{}));
+      {}, b.getIndexType(), StridedLayoutAttr::get(&ctx, /*strides=*/{}));
   EXPECT_EQ(reducedType, expectedType);
 }

``````````

</details>


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


More information about the Mlir-commits mailing list