-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang] Add support for -fcx-limited-range, #pragma CX_LIMITED_RANGE and -fcx-fortran-rules. #70244
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
Conversation
This reverts commit a3a7d63. When compiling with MSVC2022 in C++32 mode this is giving an error. Compiling this simple test case: t1.cpp: with -std=c++23 will give the following error: In file included from C:\Users\zahiraam\t1.cpp:1: c:\Program files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3329:16: error: compile with '-ffixed-point' to enable fixed point types 3329 | _Vbase _Accum = 0; | ^ c:\Program files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include\vector:3329:23: error: expected unqualified-id 3329 | _Vbase _Accum = 0; | ^ Please full error in llvm#67750 (comment)
✅ With the latest revision this PR passed the C/C++ code formatter. |
Summary: This should be `kind` and not `arch`.
This PR fixes the incorrect `mov` instruction in PTX. We actually move a predicate here, not u32, so the correct instruction should be `mov.pred`.
If gpu.alloc has no asyn deependency ( in case if gpu.alloc has hostShared allocation), create a new stream & synchronize. This PR is follow up to llvm#66401
When a target sets LLVM_ENABLE_RUNTIMES, we should only generate proxy targets for those runtimes rather than using the global list which may contain runtimes that are not supported by that particular target.
…70229) Summary: This patch simply adds the `-fconvergent-functions` flag to the GPU compilation. This is in relation to the behaviour of SIMT architectures under divergence. With the flag, we assume every function is convergent by default and rely on the compiler's divergence analysis to transform it if possible. Fixes: llvm#63853
…tion (llvm#70228) Summary: While this is technically a no-op for AMDGPU hardware, in cases where the user would see fit to add an explicit wavefront sync on Nvidia hardware, we should also inform the LLVM optimizer that this control flow is convergent so we do not reorder blocks.
This includes support for using GPRs, FPRs, and stack.
…et (llvm#69399) This is pre-cursor patch to enabling type units with DWARF5 acceleration tables. With this change it allows for entries to contain offsets directly, this way type units do not need to be preserved until .debug_names is written out.
…with F/D extensions. (llvm#69804) This a simple patch to get initial FP support started.
…with F/D extensions. (llvm#69805) This includes the plumbing for ValueMapping and PartialMapping.
…#69388) [lldb] Refactor InstrumentationRuntimeAsan and add a new plugin InstrumentationRuntimeLibsanitizers. This commit refactors InstrumentationRuntimeASan by pulling out reusable code into a separate ReportRetriever class. The purpose of the refactoring is to allow reuse of the ReportRetriever class in another plugin. The commit also adds InstrumentationRuntimeASanLibsanitizers, a new runtime plugin for ASan. The plugin provides the same functionality as InstrumentationRuntimeASan, but provides a different set of symbols/library names to search for while activating the plugin. rdar://112491689
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.
The PR summary seems to say that -ffast-math
enables -fcx-fortran-rules
, but the GCC documentations says that it enables -fcx-limited-range
. Also, where is that implemented? Should the pragma override it?
clang/lib/CodeGen/CGExprComplex.cpp
Outdated
return Call; | ||
} | ||
|
||
// EmitRangeReductionDiv - Implements the Smith's algorithm. |
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.
// EmitRangeReductionDiv - Implements the Smith's algorithm. | |
// EmitRangeReductionDiv - Implements Smith's algorithm for complex division. |
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.
Done.
@@ -220,6 +220,10 @@ BENIGN_LANGOPT(NoSignedZero , 1, 0, "Permit Floating Point optimization wit | |||
BENIGN_LANGOPT(AllowRecip , 1, 0, "Permit Floating Point reciprocal") | |||
BENIGN_LANGOPT(ApproxFunc , 1, 0, "Permit Floating Point approximation") | |||
|
|||
ENUM_LANGOPT(ComplexRange, ComplexRangeKind, 2, CX_Full, "Enable use of range reduction for complex arithmetics.") | |||
LANGOPT(CxLimitedRange, 1, 0, "Enable use of algebraic expansions of complex arithmetics.") | |||
LANGOPT(CxFortranRules, 1, 0, "Enable use of range reduction for complex arithmetics.") |
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.
Are these not redundant?
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.
Yes. Thanks.
|
||
def complex_range_EQ : Joined<["-"], "complex-range=">, Group<f_Group>, | ||
Visibility<[CC1Option]>, | ||
Values<"cx_full,cx_limited,cx_fortran">, NormalizedValuesScope<"LangOptions">, |
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.
Why the cx_
prefix?
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.
Removed.
as it's done in GCC.
"The PR summary seems to say that -ffast-math enables -fcx-fortran-rules, but the GCC documentations says that it enables -fcx-limited-range. Also, where is that implemented? Should the pragma override it?" |
clang/lib/CodeGen/CGExprComplex.cpp
Outdated
llvm::Value *AD = Builder.CreateFMul(LHSr, RHSi); // ad | ||
llvm::Value *DSTi = Builder.CreateFAdd(BC, AD); // bc+ad | ||
return ComplexPairTy(DSTr, DSTi); | ||
} |
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.
Can we just do this as a check in the code below right after we emit ResR
and ResI
? Everything before that seems to be the same.
clang/lib/CodeGen/CGExprComplex.cpp
Outdated
CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op.FPFeatures); | ||
if (RHSi && !CGF.getLangOpts().FastMath) { | ||
if (RHSi && Op.FPFeatures.getComplexRange() == LangOptions::CX_Fortran) { |
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.
Can we just hoist the !RHSi
case up here? That would simplify a lot of these conditions. And if you have it early-exit, you can also have a single check for !LHSi
instead of repeating it in every block.
clang/docs/ReleaseNotes.rst
Outdated
multiplication and enables application of Smith's algorithm for complex | ||
division. See SMITH, R. L. Algorithm 116: Complex division. Commun. ACM 5, 8 | ||
(1962). The default is ``-fno-cx-fortran-rules``, but this option is enabled by | ||
``-ffast-math``. |
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.
Should we also talk about this in the main documentation, and not just the release notes?
clang/docs/ReleaseNotes.rst
Outdated
@@ -872,6 +883,9 @@ Floating Point Support in Clang | |||
``__builtin_exp10f128`` builtins. | |||
- Add ``__builtin_iszero``, ``__builtin_issignaling`` and | |||
``__builtin_issubnormal``. | |||
- ``#pragma STDC CX_LIMITED_RANGE on-off-switch`` enables the naive mathematical | |||
formulas for complex division and multiplication with no NaN checking of | |||
results. |
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.
Suggestion:
- Add support for C99's ``#pragma STDC CX_LIMITED_RANGE` feature. This
enables the naive mathematical formulas for complex multiplication and division,
which are faster but do not correctly handle overflow and infinities.
I think we should add a __has_feature
check for this and document it here.
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.
The feature would be the pragma?
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.
Yes. Code should be able to check for whether the pragma is supported.
@rjmccall Aaron has objected to the change I made in Pragma.cpp:992 (call to DiscardUntilEndOfDirective) but I think it's correct (I have put it back)? |
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.
Thanks, the refactor in division looks a lot better. My comment about the multiplication path still stands. Otherwise, I think this is pretty close. Aaron, are your concerns addressed?
Sorry! I missed that. |
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.
LGTM. Please give the other reviewers a day or two in case they have more feedback.
Thank you! |
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.
LGTM!
@zahiraam I'd suggest you edit the commit message next time when you merge, all the merged commits should not be mentioned in the co-authored-by list. |
@arichardson Sorry I didn't notice that. Is there something I can do at this point? |
No it's in the repository now so effectively immutable. It's not a big deal just letting you know for future patches. |
Thanks! will watch for it next time. |
This patch adds the #pragma CX_LIMITED_RANGE defined in the C specification.
It also adds the options -f[no]cx-limited-range and -f[no]cx-fortran-rules.
-fcx-limited-range enables algebraic formulas for complex multiplication and division. This option is enabled with -ffast-math.
-fcx-fortran-rules enables algebraic formulas for complex multiplication and enables Smith’s algorithm for complex division (SMITH, R. L. Algorithm 116: Complex division. Commun. ACM 5, 8 (1962)).