-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
…_FALSE/TRUE macros
__GNUC__ is also defined for __clang__, so this change preserves the logic.
|
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 |
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 |
Hmm, interesting. Thank you for the pointer. Also, assume might then have different drawbacks depending on the compiler, which is rather annoying. |
04609cd
to
41ae823
Compare
I removed the use of the macro and force-pushed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
41ae823
to
e30021b
Compare
FYI: I messed up a bit on the last force push and didn't include the alphabetizing macros commit. Nothing else was lost though. |
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. |
…#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 <[email protected]> Signed-off-by: Felipe Oliveira Carvalho <[email protected]>
…#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 <[email protected]> Signed-off-by: Felipe Oliveira Carvalho <[email protected]>
…#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 <[email protected]> Signed-off-by: Felipe Oliveira Carvalho <[email protected]>
…#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 <[email protected]> Signed-off-by: Felipe Oliveira Carvalho <[email protected]>
…#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 <[email protected]> Signed-off-by: Felipe Oliveira Carvalho <[email protected]>
…#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 <[email protected]> Signed-off-by: Felipe Oliveira Carvalho <[email protected]>
…#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 <[email protected]> Signed-off-by: Felipe Oliveira Carvalho <[email protected]>
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?
macros.h
ARROW_COMPILER_ASSUME
Are these changes tested?
By existing tests.