LLVM IR already allows floating point type in atomicrmw.
Update clang atomic fetch max/min builtins to accept
floating point type like we did for fetch add/sub.
Details
- Reviewers
rjmccall tra - Commits
- rG00448a548c4e: [clang] Allow fp in atomic fetch max/min builtins
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
The code changes look OK to me.
Whether allowing FP for clang builtins is OK -- I have no idea, especially for the c11 ones.
hardware atomic fmax/fmin instructions are added because users have such needs. Their adoption in LLVM IR is to facilitate such needs. Then again in clang builtins. For users who would like to use clang builtins to access atomic fmax/fmin, it is a natural extension for the existing clang builtins since otherwise, they have to use LLVM intrinsics. Uniformly extending all clang builtins simplifies the code and also facilitates the language APIs to extend to atomic fmax/fmin. I think this is the rationale we did this for atomic fadd/fsub.
As I said, I'm OK with the patch in principle, I just don't know what other factors I may be missing.
Tests seem to be missing for c11 variants of the builtins.
clang/test/Sema/atomic-ops.c | ||
---|---|---|
219 | Is that intentional that we now allow atomic max on a int **P ? My understanding that we were supposed to allow additional FP types only. | |
clang/test/SemaOpenCL/atomic-ops.cl | ||
65 | We probably want to add tests for double, too. |
clang/lib/Sema/SemaChecking.cpp | ||
---|---|---|
6586–6589 | Collapse into a single if statement: if (!(ValType->isFloatingType() && (AllowedType & AOAVT_FP))) | |
6597 | Why do we expect a failed IsAllowedValueType check to fail only if we were allowed integers? Is that because we assume that all atomic instructions support integers? If that's the case, I'd hoist the assertion and apply it right after we're done setting ArithAllows. Alternatively, we could discard AOAVT_Integer and call the enum ArithOpExtraValueType. Tracking a bit that's always set does not buy us much, though it does make the code a bit more uniform. Up to you. |
LGTM with few more test nits.
clang/test/Sema/atomic-ops.c | ||
---|---|---|
134 | I wonder why we have this inconsistency in the non-atomic arguments. | |
218–222 | We seem to be missing the tests for double * here, too. |
Collapse into a single if statement: if (!(ValType->isFloatingType() && (AllowedType & AOAVT_FP)))