Skip to content

Commit 316b23e

Browse files
committed
[CIR] Fold ComplexRealOp from ComplexCreateOp
1 parent e29ac9b commit 316b23e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,11 @@ LogicalResult cir::ComplexRealOp::verify() {
20662066
}
20672067

20682068
OpFoldResult cir::ComplexRealOp::fold(FoldAdaptor adaptor) {
2069+
if (auto complexCreateOp = dyn_cast_or_null<cir::ComplexCreateOp>(
2070+
getOperand().getDefiningOp())) {
2071+
return complexCreateOp.getOperand(0);
2072+
}
2073+
20692074
auto complex =
20702075
mlir::cast_if_present<cir::ConstComplexAttr>(adaptor.getOperand());
20712076
return complex ? complex.getReal() : nullptr;

clang/test/CIR/Transforms/complex-real-fold.cir

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: cir-opt %s -cir-canonicalize -o - | FileCheck %s
1+
// RUN: cir-opt %s -cir-canonicalize -o - -split-input-file | FileCheck %s
22

33
!s32i = !cir.int<s, 32>
44

@@ -21,3 +21,19 @@ module {
2121
// CHECK: }
2222

2323
}
24+
25+
// -----
26+
27+
!s32i = !cir.int<s, 32>
28+
29+
module {
30+
cir.func dso_local @fold_complex_real_from_create_test(%arg0: !s32i, %arg1: !s32i) -> !s32i {
31+
%0 = cir.complex.create %arg0, %arg1 : !s32i -> !cir.complex<!s32i>
32+
%1 = cir.complex.real %0 : !cir.complex<!s32i> -> !s32i
33+
cir.return %1 : !s32i
34+
}
35+
36+
// CHECK: cir.func dso_local @fold_complex_real_from_create_test(%[[ARG_0:.*]]: !s32i, %[[ARG_1:.*]]: !s32i) -> !s32i {
37+
// CHECK: cir.return %[[ARG_0]] : !s32i
38+
// CHECK: }
39+
}

0 commit comments

Comments
 (0)