From bba9209f1d198efc7e492f0e273fff0b0a5ef060 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Tue, 16 May 2023 10:54:25 +0200 Subject: [PATCH] [MemRefToLLVM][NFC] Use early exit for the getter of the buffer ptr Address review comment from https://reviews.llvm.org/D148947 --- mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp b/mlir/lib/Conversion/LLVMCommon/MemRefBuilder.cpp index df9dafc..2c9580e 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(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(loc, ptr.getType(), elementType, ptr, + offsetVal); return ptr; } -- 2.7.4