[Mlir-commits] [mlir] bba9209 - [MemRefToLLVM][NFC] Use early exit for the getter of the buffer ptr
Quentin Colombet
llvmlistbot at llvm.org
Tue May 16 01:58:20 PDT 2023
Author: Quentin Colombet
Date: 2023-05-16T10:54:25+02:00
New Revision: bba9209f1d198efc7e492f0e273fff0b0a5ef060
URL: https://github.com/llvm/llvm-project/commit/bba9209f1d198efc7e492f0e273fff0b0a5ef060
DIFF: https://github.com/llvm/llvm-project/commit/bba9209f1d198efc7e492f0e273fff0b0a5ef060.diff
LOG: [MemRefToLLVM][NFC] Use early exit for the getter of the buffer ptr
Address review comment from https://reviews.llvm.org/D148947
Added:
Modified:
mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp
Removed:
################################################################################
diff --git a/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp b/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp
index df9dafc2d696c..2c9580e421340 100644
--- a/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp
@@ -205,17 +205,19 @@ Value MemRefDescriptor::bufferPtr(OpBuilder &builder, Location loc,
auto [strides, offsetCst] = getStridesAndOffset(type);
Value ptr = alignedPtr(builder, loc);
- // Skip if offset is zero.
- if (offsetCst != 0) {
- Type indexType = converter.getIndexType();
- Value offsetVal =
- ShapedType::isDynamic(offsetCst)
- ? offset(builder, loc)
- : createIndexAttrConstant(builder, loc, indexType, offsetCst);
- Type elementType = converter.convertType(type.getElementType());
- ptr = builder.create<LLVM::GEPOp>(loc, ptr.getType(), elementType, ptr,
- offsetVal);
- }
+ // For zero offsets, we already have the base pointer.
+ if (offsetCst == 0)
+ return ptr;
+
+ // Otherwise add the offset to the aligned base.
+ Type indexType = converter.getIndexType();
+ Value offsetVal =
+ ShapedType::isDynamic(offsetCst)
+ ? offset(builder, loc)
+ : createIndexAttrConstant(builder, loc, indexType, offsetCst);
+ Type elementType = converter.convertType(type.getElementType());
+ ptr = builder.create<LLVM::GEPOp>(loc, ptr.getType(), elementType, ptr,
+ offsetVal);
return ptr;
}
More information about the Mlir-commits
mailing list