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
1 change: 1 addition & 0 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -3107,6 +3107,7 @@ def VecCreateOp : CIR_Op<"vec.create", [Pure]> {
}];

let hasVerifier = 1;
let hasFolder = 1;
}

//===----------------------------------------------------------------------===//
Expand Down
10 changes: 10 additions & 0 deletions clang/lib/CIR/Dialect/IR/CIRDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,16 @@ void cir::StoreOp::setAtomic(cir::MemOrder order) {
// VecCreateOp
//===----------------------------------------------------------------------===//

OpFoldResult cir::VecCreateOp::fold(FoldAdaptor adaptor) {
if (llvm::any_of(getElements(), [](mlir::Value value) {
return !mlir::isa<cir::ConstantOp>(value.getDefiningOp());
}))
return {};

return cir::ConstVectorAttr::get(
getType(), mlir::ArrayAttr::get(getContext(), adaptor.getElements()));
}

LogicalResult cir::VecCreateOp::verify() {
// Verify that the number of arguments matches the number of elements in the
// vector, and that the type of all the arguments matches the type of the
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/Dialect/Transforms/CIRCanonicalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void CIRCanonicalizePass::runOnOperation() {
// CastOp, UnaryOp and VecExtractOp are here to perform a manual `fold` in
// applyOpPatternsGreedily.
if (isa<BrOp, BrCondOp, ScopeOp, SwitchOp, CastOp, TryOp, UnaryOp, SelectOp,
ComplexCreateOp, ComplexRealOp, ComplexImagOp, CallOp,
ComplexCreateOp, ComplexRealOp, ComplexImagOp, CallOp, VecCreateOp,
VecExtractOp>(op))
ops.push_back(op);
});
Expand Down
19 changes: 19 additions & 0 deletions clang/test/CIR/Transforms/vector-create-fold.cir
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: cir-opt %s -cir-canonicalize -o - | FileCheck %s

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

module {
cir.func @fold_create_vector_op_test() -> !cir.vector<!s32i x 4> {
%2 = cir.const #cir.int<1> : !s32i
%3 = cir.const #cir.int<2> : !s32i
%4 = cir.const #cir.int<3> : !s32i
%5 = cir.const #cir.int<4> : !s32i
%vec = cir.vec.create(%2, %3, %4, %5 : !s32i, !s32i, !s32i, !s32i) : !cir.vector<!s32i x 4>
cir.return %vec : !cir.vector<!s32i x 4>
}

// CHECK: cir.func @fold_create_vector_op_test() -> !cir.vector<!s32i x 4> {
// CHECK-NEXT: %[[VEC:.*]] = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<2> : !s32i,
// CHECK-SAME: #cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.vector<!s32i x 4>
// CHECK-NEXT: cir.return %[[VEC]] : !cir.vector<!s32i x 4>
}
Loading