clangir icon indicating copy to clipboard operation
clangir copied to clipboard

Cleanup `cir.scope`s with a single `cir.yield` operation

Open bcardosolopes opened this issue 1 year ago • 4 comments

This is fine, the cir.scope is created to represent the overall scope where the if codegen actually happens within (it's where init statements will place their alloca, etc). Poking at the IfStmt some layers above for this optimization isn't worth it IMO - the cleanup pass should be stripping the cir.scope here anwyays, but let me track that as a separate issue.

Originally posted by @bcardosolopes in https://github.com/llvm/clangir/pull/436#discussion_r1480861603

bcardosolopes avatar Feb 07 '24 19:02 bcardosolopes

Hi I'd like to take this issue

hardshah avatar Feb 12 '24 00:02 hardshah

Hi, @bcardosolopes I'm trying to understand exactly where I should add this cleanup pass. Is there any documentation or resources I can consult outside of the clangir website?

hardshah avatar Feb 15 '24 19:02 hardshah

@hardshah @bcardosolopes the issue's description is a bit misleading. This cleanup has already been implemented in MergeCleanupsPass:

https://github.com/llvm/clangir/blob/3d839823fab13334f493f7c71c14b30051134e89/clang/lib/CIR/Dialect/Transforms/MergeCleanups.cpp#L57-L69

The reason why it is not being applied in the empty scope that originated the issue is because of an implicit cir.yield operation that is not accounted for in the rewrite pattern's match clause.

@hardshah you can tackle this by fixing the rewrite pattern linked above.

sitio-couto avatar Feb 15 '24 20:02 sitio-couto

Okay thanks for clarifying !

hardshah avatar Feb 16 '24 23:02 hardshah