Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions tools/mlir-clang/Lib/clang-mlir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2556,8 +2556,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) {
prev.getType().dyn_cast<mlir::LLVM::LLVMPointerType>()) {
result = builder.create<LLVM::GEPOp>(
loc, pt, prev, std::vector<mlir::Value>({rhs.getValue(builder)}));
} else {
auto postTy = prev.getType().dyn_cast<mlir::IntegerType>();
} else if (auto postTy = prev.getType().dyn_cast<mlir::IntegerType>()) {
mlir::Value rhsV = rhs.getValue(builder);
auto prevTy = rhsV.getType().cast<mlir::IntegerType>();
if (prevTy == postTy) {
Expand All @@ -2572,6 +2571,18 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) {
}
assert(rhsV.getType() == prev.getType());
result = builder.create<AddIOp>(loc, prev, rhsV);
} else if (auto postTy = prev.getType().dyn_cast<mlir::MemRefType>()) {
mlir::Value rhsV = rhs.getValue(builder);
auto shape = std::vector<int64_t>(postTy.getShape());
shape[0] = -1;
postTy = mlir::MemRefType::get(shape, postTy.getElementType(),
MemRefLayoutAttrInterface(),
postTy.getMemorySpace());
auto ptradd = rhsV;
ptradd = castToIndex(loc, ptradd);
result = builder.create<polygeist::SubIndexOp>(loc, postTy, prev, ptradd);
} else {
assert(false && "Unsupported add assign type");
}
lhs.store(builder, result);
return lhs;
Expand Down
12 changes: 12 additions & 0 deletions tools/mlir-clang/Test/Verification/memrefaddassign.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: mlir-clang %s --function=* -c -S | FileCheck %s

float *foo(float *a) {
a += 32;
return a;
}
// CHECK: func @_Z3fooPf(%arg0: memref<?xf32>)
// CHECK-NEXT %c32 = arith.constant 32 : index
// CHECK-NEXT %0 = "polygeist.subindex"(%arg0, %c32) : (memref<?xf32>, index) -> memref<?xf32>
// CHECK-NEXT return %0 : memref<?xf32>
// CHECK-NEXT }