Skip to content

Commit d72e58e

Browse files
authored
[MLIR][LLVM] Propagate alignment attribute from memref to LLVM (#151380)
Propagate alignment attribute from operations in the memref dialect to the LLVM dialect. Possible improvements: maybe the alignment attribute in LLVM's store and load operations should be confined/constrained to i64? I believe that way one can avoid typing the value in the attribute dictionary. I.e., from `{ alignment = 32 : i64 }` to `{ alignment = 32}`
1 parent 6c9f1ce commit d72e58e

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,8 @@ struct LoadOpLowering : public LoadStoreOpLowering<memref::LoadOp> {
895895
adaptor.getMemref(),
896896
adaptor.getIndices(), kNoWrapFlags);
897897
rewriter.replaceOpWithNewOp<LLVM::LoadOp>(
898-
loadOp, typeConverter->convertType(type.getElementType()), dataPtr, 0,
899-
false, loadOp.getNontemporal());
898+
loadOp, typeConverter->convertType(type.getElementType()), dataPtr,
899+
loadOp.getAlignment().value_or(0), false, loadOp.getNontemporal());
900900
return success();
901901
}
902902
};
@@ -918,7 +918,8 @@ struct StoreOpLowering : public LoadStoreOpLowering<memref::StoreOp> {
918918
getStridedElementPtr(rewriter, op.getLoc(), type, adaptor.getMemref(),
919919
adaptor.getIndices(), kNoWrapFlags);
920920
rewriter.replaceOpWithNewOp<LLVM::StoreOp>(op, adaptor.getValue(), dataPtr,
921-
0, false, op.getNontemporal());
921+
op.getAlignment().value_or(0),
922+
false, op.getNontemporal());
922923
return success();
923924
}
924925
};

mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,17 @@ func.func @load_non_temporal(%arg0 : memref<32xf32, affine_map<(d0) -> (d0)>>) {
753753

754754
// -----
755755

756+
// CHECK-LABEL: func @load_with_alignment(
757+
// CHECK-INTERFACE-LABEL: func @load_with_alignment(
758+
func.func @load_with_alignment(%arg0 : memref<32xf32>, %arg1 : index) {
759+
// CHECK: llvm.load %{{.*}} {alignment = 32 : i64} : !llvm.ptr -> f32
760+
// CHECK-INTERFACE: llvm.load
761+
%1 = memref.load %arg0[%arg1] {alignment = 32} : memref<32xf32>
762+
func.return
763+
}
764+
765+
// -----
766+
756767
// CHECK-LABEL: func @store_non_temporal(
757768
// CHECK-INTERFACE-LABEL: func @store_non_temporal(
758769
func.func @store_non_temporal(%input : memref<32xf32, affine_map<(d0) -> (d0)>>, %output : memref<32xf32, affine_map<(d0) -> (d0)>>) {
@@ -766,6 +777,17 @@ func.func @store_non_temporal(%input : memref<32xf32, affine_map<(d0) -> (d0)>>,
766777

767778
// -----
768779

780+
// CHECK-LABEL: func @store_with_alignment(
781+
// CHECK-INTERFACE-LABEL: func @store_with_alignment(
782+
func.func @store_with_alignment(%arg0 : memref<32xf32>, %arg1 : f32, %arg2 : index) {
783+
// CHECK: llvm.store %{{.*}}, %{{.*}} {alignment = 32 : i64} : f32, !llvm.ptr
784+
// CHECK-INTERFACE: llvm.store
785+
memref.store %arg1, %arg0[%arg2] {alignment = 32} : memref<32xf32>
786+
func.return
787+
}
788+
789+
// -----
790+
769791
// Ensure unconvertable memory space not cause a crash
770792

771793
// CHECK-LABEL: @alloca_unconvertable_memory_space

0 commit comments

Comments
 (0)