Skip to content

Commit a23f9ed

Browse files
committed
[CIR][Transforms] Add folding for addrspace cast
1 parent a22de75 commit a23f9ed

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

clang/lib/CIR/Dialect/IR/CIRDialect.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,8 @@ OpFoldResult CastOp::fold(FoldAdaptor adaptor) {
523523
return foldResults[0].get<mlir::Attribute>();
524524
return {};
525525
}
526-
case mlir::cir::CastKind::bitcast: {
526+
case mlir::cir::CastKind::bitcast:
527+
case mlir::cir::CastKind::address_space: {
527528
return getSrc();
528529
}
529530
default:

clang/test/CIR/Transforms/merge-cleanups.cir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,13 @@ module {
126126
cir.return %0 : !cir.ptr<!s32i>
127127
}
128128

129+
// Should remove redundant address space casts.
130+
// CHECK-LABEL: @addrspacecastfold
131+
// CHECK: %[[ARG0:.+]]: !cir.ptr<!s32i, addrspace(2)>
132+
// CHECK: cir.return %[[ARG0]] : !cir.ptr<!s32i, addrspace(2)>
133+
cir.func @addrspacecastfold(%arg0: !cir.ptr<!s32i, addrspace(2)>) -> !cir.ptr<!s32i, addrspace(2)> {
134+
%0 = cir.cast(address_space, %arg0: !cir.ptr<!s32i, addrspace(2)>), !cir.ptr<!s32i, addrspace(2)>
135+
cir.return %0 : !cir.ptr<!s32i, addrspace(2)>
136+
}
137+
129138
}

0 commit comments

Comments
 (0)