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;
}