Skip to content

perf[cartesian]: avoid x + 0 and 0 + x expression in index bounds#2682

Merged
romanc merged 3 commits into
GridTools:mainfrom
romanc:romanc/avoid-x-plus-0
Jul 8, 2026
Merged

perf[cartesian]: avoid x + 0 and 0 + x expression in index bounds#2682
romanc merged 3 commits into
GridTools:mainfrom
romanc:romanc/avoid-x-plus-0

Conversation

@romanc

@romanc romanc commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Description

In oir -> treeir, avoid inserting artificial x + 0 or 0 + x calculations when translating axis bounds. In the end, this makes for cleaner generated code, which is easier to read and doesn't rely on general compilers to remove the calculation as part of their optimization pipeline.

This PR is part of cleaning up our "working branch", i.e. #2595, which accumulated a couple of changes over the last month.

Requirements

  • All fixes and/or new features come with corresponding tests.
  • Important design decisions have been documented in the appropriate ADR inside the docs/development/ADRs/ folder.
    N/A

romanc added 3 commits July 2, 2026 14:56
The conditionals for regions were generated in the form of
`{axis_bound} + {offset}`. This would lead to conditionals like

```cpp
if (((__i >= (0 + -1)) && (__i < (0 + 0)))) { ... }
```

in generated code. While we could expect compilers to handle this, it's
also ugly to work with in the intermediate representations.

This PR suggests - as a first, easy step - to detect `0` and not write
them.
@romanc
romanc requested review from FlorianDeconinck and twicki July 2, 2026 13:30

@twicki twicki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That works! Even covering for the niece end=0 case

@romanc
romanc merged commit 2b2ee24 into GridTools:main Jul 8, 2026
20 checks passed
@romanc
romanc deleted the romanc/avoid-x-plus-0 branch July 8, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants