Skip to content

Commit

Permalink
[CIR][Transforms] Add folding for addrspace cast
Browse files Browse the repository at this point in the history
  • Loading branch information
seven-mile committed Jun 4, 2024
1 parent a22de75 commit a23f9ed
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,8 @@ OpFoldResult CastOp::fold(FoldAdaptor adaptor) {
return foldResults[0].get<mlir::Attribute>();
return {};
}
case mlir::cir::CastKind::bitcast: {
case mlir::cir::CastKind::bitcast:
case mlir::cir::CastKind::address_space: {
return getSrc();
}
default:
Expand Down
9 changes: 9 additions & 0 deletions clang/test/CIR/Transforms/merge-cleanups.cir
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,13 @@ module {
cir.return %0 : !cir.ptr<!s32i>
}

// Should remove redundant address space casts.
// CHECK-LABEL: @addrspacecastfold
// CHECK: %[[ARG0:.+]]: !cir.ptr<!s32i, addrspace(2)>
// CHECK: cir.return %[[ARG0]] : !cir.ptr<!s32i, addrspace(2)>
cir.func @addrspacecastfold(%arg0: !cir.ptr<!s32i, addrspace(2)>) -> !cir.ptr<!s32i, addrspace(2)> {
%0 = cir.cast(address_space, %arg0: !cir.ptr<!s32i, addrspace(2)>), !cir.ptr<!s32i, addrspace(2)>
cir.return %0 : !cir.ptr<!s32i, addrspace(2)>
}

}

0 comments on commit a23f9ed

Please sign in to comment.