-
Notifications
You must be signed in to change notification settings - Fork 182
[CIR] Backport folder implementation for VecExtractOp #1613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,9 +79,9 @@ struct RemoveEmptyScope : public OpRewritePattern<ScopeOp> { | |
| struct RemoveEmptySwitch : public OpRewritePattern<SwitchOp> { | ||
| using OpRewritePattern<SwitchOp>::OpRewritePattern; | ||
|
|
||
| LogicalResult matchAndRewrite(SwitchOp op, PatternRewriter &rewriter) const final { | ||
| if (!(op.getBody().empty() || | ||
| isa<YieldOp>(op.getBody().front().front()))) | ||
| LogicalResult matchAndRewrite(SwitchOp op, | ||
| PatternRewriter &rewriter) const final { | ||
| if (!(op.getBody().empty() || isa<YieldOp>(op.getBody().front().front()))) | ||
| return failure(); | ||
|
|
||
| rewriter.eraseOp(op); | ||
|
|
@@ -92,7 +92,8 @@ struct RemoveEmptySwitch : public OpRewritePattern<SwitchOp> { | |
| struct RemoveTrivialTry : public OpRewritePattern<TryOp> { | ||
| using OpRewritePattern<TryOp>::OpRewritePattern; | ||
|
|
||
| LogicalResult matchAndRewrite(TryOp op, PatternRewriter &rewriter) const final { | ||
| LogicalResult matchAndRewrite(TryOp op, | ||
| PatternRewriter &rewriter) const final { | ||
| // FIXME: also check all catch regions are empty | ||
| // return success(op.getTryRegion().hasOneBlock()); | ||
| return mlir::failure(); | ||
|
|
@@ -116,7 +117,8 @@ struct RemoveTrivialTry : public OpRewritePattern<TryOp> { | |
| struct SimplifyCallOp : public OpRewritePattern<CallOp> { | ||
| using OpRewritePattern<CallOp>::OpRewritePattern; | ||
|
|
||
| LogicalResult matchAndRewrite(CallOp op, PatternRewriter &rewriter) const final { | ||
| LogicalResult matchAndRewrite(CallOp op, | ||
| PatternRewriter &rewriter) const final { | ||
| // Applicable to cir.call exception ... clean { cir.yield } | ||
| mlir::Region *r = &op.getCleanup(); | ||
| if (r->empty() || !r->hasOneBlock()) | ||
|
|
@@ -174,10 +176,11 @@ void CIRCanonicalizePass::runOnOperation() { | |
| // Collect operations to apply patterns. | ||
| llvm::SmallVector<Operation *, 16> ops; | ||
| getOperation()->walk([&](Operation *op) { | ||
| // CastOp and UnaryOp are here to perform a manual `fold` in | ||
| // CastOp, UnaryOp and VecExtractOp are here to perform a manual `fold` in | ||
| // applyOpPatternsGreedily. | ||
|
Comment on lines
+179
to
180
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @bcardosolopes do you want to keep these operations in the non-canonicalized IR?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xlauko good question, I wasn't aware of |
||
| if (isa<BrOp, BrCondOp, ScopeOp, SwitchOp, CastOp, TryOp, UnaryOp, SelectOp, | ||
| ComplexCreateOp, ComplexRealOp, ComplexImagOp, CallOp>(op)) | ||
| ComplexCreateOp, ComplexRealOp, ComplexImagOp, CallOp, | ||
| VecExtractOp>(op)) | ||
| ops.push_back(op); | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // RUN: cir-opt %s -cir-canonicalize -o - | FileCheck %s | ||
|
|
||
| !s32i = !cir.int<s, 32> | ||
|
|
||
| module { | ||
| cir.func @fold_extract_vector_op_test() { | ||
| %init = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init] | ||
| %const_vec = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.vector<!s32i x 4> | ||
| %index = cir.const #cir.int<1> : !s32i | ||
| %ele = cir.vec.extract %const_vec[%index : !s32i] : !cir.vector<!s32i x 4> | ||
| cir.store %ele, %init : !s32i, !cir.ptr<!s32i> | ||
| cir.return | ||
| } | ||
|
|
||
| // CHECK: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init] | ||
| // CHECK: %[[VALUE:.*]] = cir.const #cir.int<2> : !s32i | ||
| // CHECK: cir.store %[[VALUE]], %[[INIT]] : !s32i, !cir.ptr<!s32i> | ||
|
|
||
| cir.func @fold_extract_vector_op_index_out_of_bounds_test() { | ||
| %init = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init] | ||
| %const_vec = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.vector<!s32i x 4> | ||
| %index = cir.const #cir.int<9> : !s32i | ||
| %ele = cir.vec.extract %const_vec[%index : !s32i] : !cir.vector<!s32i x 4> | ||
| cir.store %ele, %init : !s32i, !cir.ptr<!s32i> | ||
| cir.return | ||
| } | ||
|
|
||
| // CHECK: %[[INIT:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["e", init] | ||
| // CHECK: %[[CONST_VEC:.*]] = cir.const #cir.const_vector<[#cir.int<1> : !s32i, #cir.int<2> : !s32i, #cir.int<3> : !s32i, #cir.int<4> : !s32i]> : !cir.vector<!s32i x 4> | ||
| // CHECK: %[[INDEX:.*]] = cir.const #cir.int<9> : !s32i | ||
| // CHECK: %[[ELE:.*]] = cir.vec.extract %[[CONST_VEC]][%[[INDEX]] : !s32i] : !cir.vector<!s32i x 4> | ||
| // CHECK: cir.store %[[ELE]], %[[INIT]] : !s32i, !cir.ptr<!s32i> | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.