summaryrefslogtreecommitdiff
path: root/mlir
diff options
context:
space:
mode:
Diffstat (limited to 'mlir')
-rw-r--r--mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp b/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp
index df9dafc2d696..2c9580e42134 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;
}