Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2066,6 +2066,10 @@ LogicalResult cir::ComplexRealOp::verify() {
}

OpFoldResult cir::ComplexRealOp::fold(FoldAdaptor adaptor) {
if (auto complexCreateOp =
dyn_cast_or_null<cir::ComplexCreateOp>(getOperand().getDefiningOp()))
return complexCreateOp.getOperand(0);

auto complex =
mlir::cast_if_present<cir::ConstComplexAttr>(adaptor.getOperand());
return complex ? complex.getReal() : nullptr;
Expand Down
18 changes: 17 additions & 1 deletion clang/test/CIR/Transforms/complex-real-fold.cir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: cir-opt %s -cir-canonicalize -o - | FileCheck %s
// RUN: cir-opt %s -cir-canonicalize -o - -split-input-file | FileCheck %s

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

Expand All @@ -21,3 +21,19 @@ module {
// CHECK: }

}

// -----

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

module {
cir.func dso_local @fold_complex_real_from_create_test(%arg0: !s32i, %arg1: !s32i) -> !s32i {
%0 = cir.complex.create %arg0, %arg1 : !s32i -> !cir.complex<!s32i>
%1 = cir.complex.real %0 : !cir.complex<!s32i> -> !s32i
cir.return %1 : !s32i
}

// CHECK: cir.func dso_local @fold_complex_real_from_create_test(%[[ARG_0:.*]]: !s32i, %[[ARG_1:.*]]: !s32i) -> !s32i {
// CHECK: cir.return %[[ARG_0]] : !s32i
// CHECK: }
}