[Mlir-commits] [mlir] fd86e73 - [mlir][memref][nfc] push early-exit to earlier (#140730)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Wed May 21 03:38:00 PDT 2025


Author: Javed Absar
Date: 2025-05-21T11:37:57+01:00
New Revision: fd86e732fa93c4d4a658c717b6593c179448a2aa

URL: https://github.com/llvm/llvm-project/commit/fd86e732fa93c4d4a658c717b6593c179448a2aa
DIFF: https://github.com/llvm/llvm-project/commit/fd86e732fa93c4d4a658c717b6593c179448a2aa.diff

LOG: [mlir][memref][nfc] push early-exit to earlier (#140730)

Move early exit check to as early as possible,

quic_mabsar at quicinc.com

Added: 
    

Modified: 
    mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
index ade4e4d3de8ec..339f8a61136fc 100644
--- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
+++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
@@ -1721,6 +1721,10 @@ struct ViewOpLowering : public ConvertOpToLLVMPattern<memref::ViewOp> {
     MemRefDescriptor sourceMemRef(adaptor.getSource());
     auto targetMemRef = MemRefDescriptor::poison(rewriter, loc, targetDescTy);
 
+    // Early exit for 0-D corner case.
+    if (viewMemRefType.getRank() == 0)
+      return rewriter.replaceOp(viewOp, {targetMemRef}), success();
+
     // Field 1: Copy the allocated pointer, used for malloc/free.
     Value allocatedPtr = sourceMemRef.allocatedPtr(rewriter, loc);
     auto srcMemRefType = cast<MemRefType>(viewOp.getSource().getType());
@@ -1743,10 +1747,6 @@ struct ViewOpLowering : public ConvertOpToLLVMPattern<memref::ViewOp> {
         rewriter, loc,
         createIndexAttrConstant(rewriter, loc, indexType, offset));
 
-    // Early exit for 0-D corner case.
-    if (viewMemRefType.getRank() == 0)
-      return rewriter.replaceOp(viewOp, {targetMemRef}), success();
-
     // Fields 4 and 5: Update sizes and strides.
     Value stride = nullptr, nextSize = nullptr;
     for (int i = viewMemRefType.getRank() - 1; i >= 0; --i) {


        


More information about the Mlir-commits mailing list