Skip to content
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

GH-41020: [C++] Introduce portable compiler assumptions #41021

Merged
merged 5 commits into from
Apr 9, 2024

Conversation

felipecrv
Copy link
Contributor

@felipecrv felipecrv commented Apr 5, 2024

Rationale for this change

Allow portable use of the "assumption" feature of modern GCC, Clang, and MSVC compilers.

What changes are included in this PR?

  • Documenting of macros in macros.h
  • Addition of ARROW_COMPILER_ASSUME
  • One simple change where this macro simplifies the existing code while keeping the common case of a loop branch dependent only on local variables

Are these changes tested?

By existing tests.

@felipecrv felipecrv changed the title Compiler assume GH-41020: [C++] Introduce portable compiler assumptions Apr 5, 2024
@apache apache deleted a comment from github-actions bot Apr 5, 2024
@felipecrv felipecrv requested a review from pitrou April 5, 2024 00:28
Copy link

github-actions bot commented Apr 5, 2024

⚠️ GitHub issue #41020 has been automatically assigned in GitHub to PR creator.

@github-actions github-actions bot added awaiting changes Awaiting changes awaiting change review Awaiting change review and removed awaiting committer review Awaiting committer review awaiting changes Awaiting changes labels Apr 5, 2024
@felipecrv felipecrv requested a review from pitrou April 5, 2024 14:15
@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Apr 5, 2024
@mapleFU
Copy link
Member

mapleFU commented Apr 5, 2024

I wonder would llvm / gcc have a pass or other things finding out that could it find the assertions? Seems that the rule in this case is trivial, maybe we can use this when it's not so trivial and have some benchmark shows that performance would benifits from this?

@felipecrv
Copy link
Contributor Author

I wonder would llvm / gcc have a pass or other things finding out that could it find the assertions? Seems that the rule in this case is trivial, maybe we can use this when it's not so trivial and have some benchmark shows that performance would benifits from this?

Yes, they already do a great job finding assumptions [1] and the C++ standard allows many assumptions to be made. e.g. every pointer dereference assumes that the pointer is not-null, divisors are assumed to be non-0, signed arithmetic is assumed to not overflow, etc.

[1] assertions and assumptions are very different things -> https://blog.regehr.org/archives/1096

@mapleFU
Copy link
Member

mapleFU commented Apr 5, 2024

Thanks for introducing this. IMO assume is something like restrict. And it might not only brings optimization[1]. I'm glad to have this, but when we change the code maybe we need benchmark data

[1] https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609

@pitrou
Copy link
Member

pitrou commented Apr 5, 2024

And it might not only brings optimization[1]. I'm glad to have this, but when we change the code maybe we need benchmark data

[1] https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609

Hmm, interesting. Thank you for the pointer. Also, assume might then have different drawbacks depending on the compiler, which is rather annoying.

@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Apr 5, 2024
@felipecrv
Copy link
Contributor Author

I removed the use of the macro and force-pushed.

Copy link
Member

@mapleFU mapleFU left a comment

Choose a reason for hiding this comment

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

+1

cpp/src/arrow/util/macros.h Show resolved Hide resolved
@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting change review Awaiting change review labels Apr 6, 2024
cpp/src/arrow/util/macros.h Outdated Show resolved Hide resolved
cpp/src/arrow/util/macros.h Show resolved Hide resolved
cpp/src/arrow/util/macros.h Outdated Show resolved Hide resolved
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Apr 8, 2024
@felipecrv felipecrv requested review from mapleFU and pitrou April 8, 2024 20:15
@felipecrv felipecrv merged commit aeb1618 into apache:main Apr 9, 2024
37 checks passed
@felipecrv felipecrv removed the awaiting change review Awaiting change review label Apr 9, 2024
@felipecrv felipecrv deleted the compiler_assume branch April 9, 2024 14:14
@felipecrv
Copy link
Contributor Author

FYI: I messed up a bit on the last force push and didn't include the alphabetizing macros commit. Nothing else was lost though.

Copy link

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit aeb1618.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 12 possible false positives for unstable benchmarks that are known to sometimes produce them.

verma-kartik pushed a commit to verma-kartik/arrow that referenced this pull request Apr 11, 2024
…#41021)

### Rationale for this change

Allow portable use of the "assumption" feature of modern GCC, Clang, and MSVC compilers.

### What changes are included in this PR?

 - Documenting of macros in `macros.h`
 - Addition of `ARROW_COMPILER_ASSUME`
 - One simple change where this macro simplifies the existing code while keeping the common case of a loop branch dependent only on local variables
 
### Are these changes tested?

By existing tests.
* GitHub Issue: apache#41020

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
vibhatha pushed a commit to vibhatha/arrow that referenced this pull request Apr 15, 2024
…#41021)

### Rationale for this change

Allow portable use of the "assumption" feature of modern GCC, Clang, and MSVC compilers.

### What changes are included in this PR?

 - Documenting of macros in `macros.h`
 - Addition of `ARROW_COMPILER_ASSUME`
 - One simple change where this macro simplifies the existing code while keeping the common case of a loop branch dependent only on local variables
 
### Are these changes tested?

By existing tests.
* GitHub Issue: apache#41020

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
tolleybot pushed a commit to tmct/arrow that referenced this pull request May 2, 2024
…#41021)

### Rationale for this change

Allow portable use of the "assumption" feature of modern GCC, Clang, and MSVC compilers.

### What changes are included in this PR?

 - Documenting of macros in `macros.h`
 - Addition of `ARROW_COMPILER_ASSUME`
 - One simple change where this macro simplifies the existing code while keeping the common case of a loop branch dependent only on local variables
 
### Are these changes tested?

By existing tests.
* GitHub Issue: apache#41020

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
tolleybot pushed a commit to tmct/arrow that referenced this pull request May 4, 2024
…#41021)

### Rationale for this change

Allow portable use of the "assumption" feature of modern GCC, Clang, and MSVC compilers.

### What changes are included in this PR?

 - Documenting of macros in `macros.h`
 - Addition of `ARROW_COMPILER_ASSUME`
 - One simple change where this macro simplifies the existing code while keeping the common case of a loop branch dependent only on local variables
 
### Are these changes tested?

By existing tests.
* GitHub Issue: apache#41020

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
rok pushed a commit to tmct/arrow that referenced this pull request May 8, 2024
…#41021)

### Rationale for this change

Allow portable use of the "assumption" feature of modern GCC, Clang, and MSVC compilers.

### What changes are included in this PR?

 - Documenting of macros in `macros.h`
 - Addition of `ARROW_COMPILER_ASSUME`
 - One simple change where this macro simplifies the existing code while keeping the common case of a loop branch dependent only on local variables
 
### Are these changes tested?

By existing tests.
* GitHub Issue: apache#41020

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
rok pushed a commit to tmct/arrow that referenced this pull request May 8, 2024
…#41021)

### Rationale for this change

Allow portable use of the "assumption" feature of modern GCC, Clang, and MSVC compilers.

### What changes are included in this PR?

 - Documenting of macros in `macros.h`
 - Addition of `ARROW_COMPILER_ASSUME`
 - One simple change where this macro simplifies the existing code while keeping the common case of a loop branch dependent only on local variables
 
### Are these changes tested?

By existing tests.
* GitHub Issue: apache#41020

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
vibhatha pushed a commit to vibhatha/arrow that referenced this pull request May 25, 2024
…#41021)

### Rationale for this change

Allow portable use of the "assumption" feature of modern GCC, Clang, and MSVC compilers.

### What changes are included in this PR?

 - Documenting of macros in `macros.h`
 - Addition of `ARROW_COMPILER_ASSUME`
 - One simple change where this macro simplifies the existing code while keeping the common case of a loop branch dependent only on local variables
 
### Are these changes tested?

By existing tests.
* GitHub Issue: apache#41020

Authored-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Signed-off-by: Felipe Oliveira Carvalho <felipekde@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants