Skip to content

Add vstorea_half generic-pointer support and FP64 tests - #1752

Merged
rjodinchr merged 1 commit into
google:mainfrom
cyrne1-7208:support-vstore-half-double
Nov 19, 2026
Merged

rjodinchr merged 1 commit into
google:mainfrom
cyrne1-7208:support-vstore-half-double

Conversation

@cyrne1-7208

@cyrne1-7208 cyrne1-7208 commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Part of #321 (3/4 of the final #321 FP64 completion series).

Summary

Extend Builtins::BuiltinWithGenericPointer to recognize vstorea_half*, and add lit tests covering FP64 vstore_half / vstorea_half support implemented upstream in llvm/llvm-project@9fa789fd (rolled into deps.json in #1756).

Problem

  1. Builtins::BuiltinWithGenericPointer matched vstore_half* but omitted vstorea_half(2|3|4|8|16). Calls to vstorea_half* with a generic pointer failed to retain concrete address-space libclc overloads in GetEquivalentBuiltinsWithoutGenericPointer and skip pre-lowering in ReplaceOpenCLBuiltinPass.
  2. clspv lacked lit tests exercising double vstore_half / vstorea_half lowering across rounding modes, vector widths, storage options, and generic pointers.

Change

  • Extend Builtins::BuiltinWithGenericPointer in lib/Builtins.cpp with vstorea_half(2|3|4|8|16)(_rte|_rtz|_rtp|_rtn)? using StringRef::starts_with prefiltering (still excluding non-OpenCL scalar vstorea_half).
  • Add generic-pointer regression coverage in test/BuiltinsWithGenericPointer/ (vstorea_half_print.cl, vstore_half_double.cl, and vstorea_half* negative cases in issue-1343.cl).
  • Add FP64 vstore_half / vstorea_half lit tests in test/HalfStorage/ (vstore_half_double.cl, vstore_half_double_vectors.cl, vstore_half8_double.cl, and vstore_half_double_rounding.cl).

Testing

  • Added tests covering scalar and vector widths 2/3/4/8 (-no-16bit-storage=ssbo, -vec3-to-vec4, --long-vector, -O0), global/local/private/generic (CL2.0, CL3.0, CLC++), and IEEE-754 double-rounding/edge cases (±0, +Inf, NaN, saturation), validated with spirv-val.
  • Rebased onto main (Update LLVM #1756, deps.json at 944a108b) and verified lit.py --filter="(BuiltinsWithGenericPointer|HalfStorage)" passes 70/70 tests on both -arch=spirv32 and -arch=spirv64 (with libclc vstore_half.{cl,inc} from 944a108b; the initial revision also passed full ninja check-spirv and ninja check-spirv-64 3978/3978 against llvm/llvm-project@9fa789fd).

@rjodinchr rjodinchr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why not implement the double overloads in libclc (opencl/lib/spirv/vulkan/shared/vstore_half.cl and vstore_half.inc), just like float?

libclc already has the double rounding helpers (__clc_rtz, __clc_rti, __clc_rtn, __clc_rtp, __clc_rte) in clc/lib/generic/shared/clc_vstore.cl. Since any half-rounded value is exactly representable as a float, the double definitions in vstore_half.cl could round the double, convert it to float, and call the existing vstore_half_N(floatN, ...) / vstorea_half_N(floatN, ...) helpers. That would avoid duplicating the IEEE-754 rounding logic in getVstoreHalfValue and avoid having to register all the user-facing vstore_half* builtins in BuiltinsMap.inc and special-case them in NativeMathPass / replaceVstoreHalf.

@cyrne1-7208

Copy link
Copy Markdown
Contributor Author

Agreed, implementing the double overloads in libclc is much cleaner and avoids getVstoreHalfValue, BuiltinsMap.inc, and the NativeMathPass/replaceVstoreHalf workarounds.

However, the existing double helpers in clc_vstore.cl lack Vulkan vstore_half.cl's boundary fixes (exp < -24, == 0, > 0x1.ffcp+15) and aren't cleanly shared without header declarations and symbol deduplication. With no open llvm/llvm-project PRs addressing this, taking that route would require an upstream PR (and a deps.json update) first.

Would you prefer that I pursue the llvm/llvm-project PR first, or keep this self-contained in clspv? Since this is a fundamental rethink, I'll convert this PR to draft for now.

@cyrne1-7208
cyrne1-7208 marked this pull request as draft November 15, 2026 10:30
@rjodinchr

Copy link
Copy Markdown
Collaborator

Yes, please proceed with the upstream libclc (llvm/llvm-project) change first! Adding the double helpers (with the boundary checks) and overloads in opencl/lib/spirv/vulkan/shared/vstore_half.cl / vstore_half.inc so they round and forward to the existing vstore_half_N / vstorea_half_N helpers will keep clspv much cleaner. Once that lands upstream, we can roll deps.json and land the BuiltinWithGenericPointer fix and tests here.

@cyrne1-7208

Copy link
Copy Markdown
Contributor Author

Sounds good, thank you for confirming the direction!❤️ I'll work on the upstream llvm/llvm-project PR first, and drop a link here once it's opened.

@cyrne1-7208

Copy link
Copy Markdown
Contributor Author

Opened the upstream libclc PR for Vulkan vstore_half and vstorea_half double support: llvm/llvm-project#242829

wenju-he pushed a commit to llvm/llvm-project that referenced this pull request Nov 16, 2026
…#242829)

Implement `double` overloads for `vstore_half` and `vstorea_half` under
`cl_khr_fp64`. Round each element with the Vulkan boundary checks, then
forward it as `float` to the existing `vstore_half_N` and
`vstorea_half_N` helpers.

Prerequisite for google/clspv#1752; end-to-end tests will be added there
since `libclc/test` currently targets only AMDGPU.

I used AI assistance to prepare and review this patch.
I reviewed the entire change and take full responsibility for this PR.

Assisted-by: Antigravity Gemini 4 Hydrogen Extra reasoning
Assisted-by: Claude Code Opus 5.5 Max reasoning
llvm-upstreamsync Bot pushed a commit to qualcomm/cpullvm-toolchain that referenced this pull request Nov 16, 2026
…storea_half (#242829)

Implement `double` overloads for `vstore_half` and `vstorea_half` under
`cl_khr_fp64`. Round each element with the Vulkan boundary checks, then
forward it as `float` to the existing `vstore_half_N` and
`vstorea_half_N` helpers.

Prerequisite for google/clspv#1752; end-to-end tests will be added there
since `libclc/test` currently targets only AMDGPU.

I used AI assistance to prepare and review this patch.
I reviewed the entire change and take full responsibility for this PR.

Assisted-by: Antigravity Gemini 4 Hydrogen Extra reasoning
Assisted-by: Claude Code Opus 5.5 Max reasoning
llvm-sync Bot pushed a commit to arm/arm-toolchain that referenced this pull request Nov 16, 2026
…storea_half (#242829)

Implement `double` overloads for `vstore_half` and `vstorea_half` under
`cl_khr_fp64`. Round each element with the Vulkan boundary checks, then
forward it as `float` to the existing `vstore_half_N` and
`vstorea_half_N` helpers.

Prerequisite for google/clspv#1752; end-to-end tests will be added there
since `libclc/test` currently targets only AMDGPU.

I used AI assistance to prepare and review this patch.
I reviewed the entire change and take full responsibility for this PR.

Assisted-by: Antigravity Gemini 4 Hydrogen Extra reasoning
Assisted-by: Claude Code Opus 5.5 Max reasoning
@cyrne1-7208
cyrne1-7208 force-pushed the support-vstore-half-double branch from 4ca37f2 to 055adf7 Compare November 16, 2026 01:39
@cyrne1-7208 cyrne1-7208 changed the title Add double support for vstore_half and vstorea_half Add vstorea_half generic-pointer support and FP64 tests Nov 16, 2026
@cyrne1-7208

Copy link
Copy Markdown
Contributor Author

llvm/llvm-project#242829 has been merged upstream as 9fa789fd. I've updated this PR to keep only the BuiltinWithGenericPointer fix and tests, and verified it locally against that commit.

Keeping this as a draft until deps.json rolls past 9fa789fd for CI.

@rjodinchr

Copy link
Copy Markdown
Collaborator

You can rebase that PR once #1756 lands

@cyrne1-7208

Copy link
Copy Markdown
Contributor Author

You can rebase that PR once #1756 lands

Thanks!❤️

@cyrne1-7208
cyrne1-7208 marked this pull request as ready for review November 19, 2026 12:18
@cyrne1-7208

cyrne1-7208 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

Sorry, I forgot to rebase first so CI ran with the old deps.json.
Rebasing onto #1756 now!

Part of google#321 (3/4 of the final `google#321` FP64 completion series).

## Summary

Extend `Builtins::BuiltinWithGenericPointer` to recognize `vstorea_half*`, and add lit tests covering FP64 `vstore_half` / `vstorea_half` support implemented upstream in `llvm/llvm-project@9fa789fd` (rolled into `deps.json` in google#1756).

## Problem

1. `Builtins::BuiltinWithGenericPointer` matched `vstore_half*` but omitted `vstorea_half(2|3|4|8|16)`. Calls to `vstorea_half*` with a generic pointer failed to retain concrete address-space `libclc` overloads in `GetEquivalentBuiltinsWithoutGenericPointer` and skip pre-lowering in `ReplaceOpenCLBuiltinPass`.
2. `clspv` lacked lit tests exercising `double` `vstore_half` / `vstorea_half` lowering across rounding modes, vector widths, storage options, and generic pointers.

## Change

- Extend `Builtins::BuiltinWithGenericPointer` in `lib/Builtins.cpp` with `vstorea_half(2|3|4|8|16)(_rte|_rtz|_rtp|_rtn)?` using `StringRef::starts_with` prefiltering (still excluding non-OpenCL scalar `vstorea_half`).
- Add generic-pointer regression coverage in `test/BuiltinsWithGenericPointer/` (`vstorea_half_print.cl`, `vstore_half_double.cl`, and `vstorea_half*` negative cases in `issue-1343.cl`).
- Add FP64 `vstore_half` / `vstorea_half` lit tests in `test/HalfStorage/` (`vstore_half_double.cl`, `vstore_half_double_vectors.cl`, `vstore_half8_double.cl`, and `vstore_half_double_rounding.cl`).

## Testing

- Added tests covering scalar and vector widths `2`/`3`/`4`/`8` (`-no-16bit-storage=ssbo`, `-vec3-to-vec4`, `--long-vector`, `-O0`), `global`/`local`/`private`/`generic` (`CL2.0`, `CL3.0`, `CLC++`), and IEEE-754 double-rounding/edge cases (`±0`, `+Inf`, `NaN`, saturation), validated with `spirv-val`.
- Rebased onto `main` (google#1756, `deps.json` at `944a108b`) and verified `lit.py --filter="(BuiltinsWithGenericPointer|HalfStorage)"` passes `70/70` tests on both `-arch=spirv32` and `-arch=spirv64` (with `libclc` `vstore_half.{cl,inc}` from `944a108b`; the initial revision also passed full `ninja check-spirv` and `ninja check-spirv-64` `3978/3978` against `llvm/llvm-project@9fa789fd`).
@cyrne1-7208
cyrne1-7208 force-pushed the support-vstore-half-double branch from 055adf7 to 51aabf7 Compare November 19, 2026 13:26
@rjodinchr
rjodinchr enabled auto-merge (squash) November 19, 2026 13:33
@rjodinchr
rjodinchr merged commit 5806702 into google:main Nov 19, 2026
17 of 18 checks passed
cyrne1-7208 added a commit to cyrne1-7208/clspv that referenced this pull request Nov 19, 2026
Fixes google#321.

Final PR (4/4) of the `google#321` FP64 completion series following google#1750, google#1751, and google#1752.

## Summary

Keep `libclc` software implementations for FP64 math builtins that lack 64-bit `GLSL.std.450` support in Vulkan SPIR-V under `--cl-native-math` / `--use-native-builtins`, add dedicated `double` operator tests, and remove the stale incomplete-FP64 note from `docs/OpenCLCOnVulkan.md`.

## Problem

In SPIR-V `GLSL.std.450`, transcendental and power/logarithmic instructions (`Acos`, `Acosh`, `Asin`, `Asinh`, `Atan`, `Atanh`, `Atan2`, `Sin`, `Sinh`, `Cos`, `Cosh`, `Tan`, `Tanh`, `Exp`, `Exp2`, `Log`, `Log2`, `Pow`) only support 16-bit and 32-bit floats. Under `--cl-native-math` or `--use-native-builtins`, `NativeMathPass` deleted the `libclc` bodies of `double` math builtins regardless of type, either emitting invalid 64-bit `GLSL.std.450` instructions (`spirv-val` failure) or lowering via `ReplaceOpenCLBuiltinPass` into unlowered `llvm.sincos` (`sincos`, `tanpi`), which also broke transitive `libclc` callers such as `erf`, `erfc`, `lgamma`, `lgamma_r`, `tgamma`, and `rootn`. In addition, the `64-Bit Floating-Point Types` documentation still carried the note pointing to issue 321, and there was no standalone `double` operator lit test.

## Change

- In `lib/NativeMathPass.cpp`, add `is_unsupported_fp64_glsl_op` and `keep_fp64_libclc_body` to retain `libclc` bodies (`!F.isDeclaration() && F.getReturnType()->getScalarType()->isDoubleTy()`) for:
  - builtins mapping via `Builtins::getExtInstEnum` to the 18 16/32-bit-only `GLSL.std.450` ops above (covering `sin..powr` and `acospi..atan2pi`), and
  - `ReplaceableBuiltins` math lowerings that expand to them (`exp10`, `expm1`, `log10`, `log1p`, `pown`, `cospi`, `sinpi`, `tanpi`, `sincos`).
- Guard both body deletion (`have_native_impl`) and the `--use-native-builtins` unsupported-builtin error with `!keep_libclc_body`, leaving `float` native math and 64-bit native-capable builtins (`sqrt`, `rsqrt`, `floor`, `ceil`, `trunc`, `rint`, `fma`, `fmin`, `fmax`, `mix`, `step`, `smoothstep`, `sign`, `ldexp`, `frexp`, `fract`, `length`, `distance`, `normalize`, `cross`, `degrees`, `radians`, etc.) untouched.
- Add `test/double_operators.cl` covering scalar and vector `double` arithmetic, negation, comparisons, and ternary selection (default and `-vec3-to-vec4`).
- Add `test/NativeBuiltins/MathBuiltins/double_native_math.cl`, `double_mixed_float.cl`, and `double_native_capable.cl`.
- Remove the obsolete incomplete-FP64 note referencing issue 321 in `docs/OpenCLCOnVulkan.md`.

## Testing

- Verified `double_operators.cl`, `double_native_math.cl`, `double_mixed_float.cl`, and `double_native_capable.cl` across scalar and vector `double` (`-vec3-to-vec4`, `--cl-native-math`, and `--use-native-builtins`) with `spirv-val --target-env vulkan1.0` (both `-arch=spirv32` and `-arch=spirv64`).
- Rebased onto `main` (google#1752, `58067020`) and verified `lit.py --filter="(NativeBuiltins|double_operators)"` passes `193/193` tests on both `-arch=spirv32` and `-arch=spirv64` (`3,790` unrelated tests excluded; the pre-rebase revision also passed `ninja check-spirv` and `ninja check-spirv-64` with `3969/3969`, and `3982/3982` when stacked with google#1750–google#1752).
@cyrne1-7208
cyrne1-7208 deleted the support-vstore-half-double branch November 19, 2026 15:21
cyrne1-7208 added a commit to cyrne1-7208/clspv that referenced this pull request Nov 19, 2026
Ref google#321.

Series follow-up PR (4/4) for google#321 following google#1750, google#1751, and google#1752 (remaining pre-existing FP64 edge cases are tracked in google#321).

## Summary

Keep `libclc` software implementations for FP64 math builtins that lack 64-bit `GLSL.std.450` support in Vulkan SPIR-V under `--cl-native-math` / `--use-native-builtins`, add dedicated `double` operator tests, and remove the stale incomplete-FP64 note from `docs/OpenCLCOnVulkan.md`.

## Problem

In SPIR-V `GLSL.std.450`, angle-conversion, transcendental, and power/logarithmic instructions (`Radians`, `Degrees`, `Acos`, `Acosh`, `Asin`, `Asinh`, `Atan`, `Atanh`, `Atan2`, `Sin`, `Sinh`, `Cos`, `Cosh`, `Tan`, `Tanh`, `Exp`, `Exp2`, `Log`, `Log2`, `Pow`) only support 16-bit and 32-bit floats. Under `--cl-native-math` or `--use-native-builtins`, `NativeMathPass` deleted the `libclc` bodies of `double` math builtins regardless of type, either emitting invalid 64-bit `GLSL.std.450` instructions (`spirv-val` failure) or lowering via `ReplaceOpenCLBuiltinPass` into unlowered `llvm.sincos` (`sincos`, `tanpi`), which also broke transitive `libclc` callers such as `erf`, `erfc`, `lgamma`, `lgamma_r`, `tgamma`, and `rootn` (and relied on downstream `ReplaceOpenCLBuiltinPass::replaceDegreesOrRadians` for FP64 `degrees` / `radians`). In addition, the `64-Bit Floating-Point Types` documentation still carried the note pointing to issue 321, and there was no standalone `double` operator lit test.

## Change

- In `lib/NativeMathPass.cpp`, add `is_unsupported_fp64_glsl_op` and `keep_fp64_libclc_body` to retain `libclc` bodies (`!F.isDeclaration() && F.getReturnType()->getScalarType()->isDoubleTy()`) for:
  - builtins mapping via `Builtins::getExtInstEnum` to the 20 16/32-bit-only `GLSL.std.450` ops above (covering `radians`, `degrees`, `sin..powr`, and `acospi..atan2pi`), and
  - `ReplaceableBuiltins` math lowerings that expand to them (`exp10`, `expm1`, `log10`, `log1p`, `pown`, `cospi`, `sinpi`, `tanpi`, `sincos`).
- Guard both body deletion (`have_native_impl`) and the `--use-native-builtins` unsupported-builtin error with `!keep_libclc_body`, leaving `float` native math and 64-bit native-capable GLSL/IR builtins (`sqrt`, `rsqrt`, `floor`, `ceil`, `trunc`, `rint`, `fma`, `fmin`, `fmax`, `mix`, `step`, `smoothstep`, `sign`, `ldexp`, `frexp`, `fract`, `length`, `distance`, `normalize`, `cross`, etc.) untouched (while FP64 `degrees` / `radians` lower to `FMul` via `libclc` / `ReplaceOpenCLBuiltinPass`).
- Add `test/double_operators.cl` covering scalar and vector `double` arithmetic, negation, comparisons, and ternary selection (default and `-vec3-to-vec4`).
- Add `test/NativeBuiltins/MathBuiltins/double_native_math.cl`, `double_mixed_float.cl` (capturing `fp64_double`, `fp64_v3double` where `OpTypeVector <double> 3` is emitted, and `fp64_v4double`), and `double_native_capable.cl`.
- Remove the obsolete incomplete-FP64 note referencing issue 321 in `docs/OpenCLCOnVulkan.md`.

## Testing

- Verified `lit.py --filter="(NativeBuiltins|double_operators|double_degrees_radians)"` passes `195/195` tests on both `-arch=spirv32` and `-arch=spirv64` (`3,788` unrelated tests excluded), including `--cl-native-math`, `--use-native-builtins`, and `-vec3-to-vec4` with `spirv-val --target-env vulkan1.0`.
cyrne1-7208 added a commit to cyrne1-7208/clspv that referenced this pull request Nov 20, 2026
Ref google#321.

Series follow-up PR (4/4) for google#321 following google#1750, google#1751, and google#1752 (remaining pre-existing FP64 edge cases are tracked in google#321).

## Summary

Keep `libclc` software implementations for FP64 math builtins that lack 64-bit `GLSL.std.450` support in Vulkan SPIR-V under `--cl-native-math` / `--use-native-builtins`, add dedicated `double` operator tests.

## Problem

In SPIR-V `GLSL.std.450`, angle-conversion, transcendental, and power/logarithmic instructions (`Radians`, `Degrees`, `Acos`, `Acosh`, `Asin`, `Asinh`, `Atan`, `Atanh`, `Atan2`, `Sin`, `Sinh`, `Cos`, `Cosh`, `Tan`, `Tanh`, `Exp`, `Exp2`, `Log`, `Log2`, `Pow`) only support 16-bit and 32-bit floats. Under `--cl-native-math` or `--use-native-builtins`, `NativeMathPass` deleted the `libclc` bodies of `double` math builtins regardless of type, either emitting invalid 64-bit `GLSL.std.450` instructions (`spirv-val` failure) or lowering via `ReplaceOpenCLBuiltinPass` into unlowered `llvm.sincos` (`sincos`, `tanpi`), which also broke transitive `libclc` callers such as `erf`, `erfc`, `lgamma`, `lgamma_r`, `tgamma`, and `rootn` (and relied on downstream `ReplaceOpenCLBuiltinPass::replaceDegreesOrRadians` for FP64 `degrees` / `radians`). In addition, there was no standalone `double` operator lit test.

## Change

- In `lib/NativeMathPass.cpp`, add `is_unsupported_fp64_glsl_op` and `keep_fp64_libclc_body` to retain `libclc` bodies (`!F.isDeclaration() && F.getReturnType()->getScalarType()->isDoubleTy()`) for:
  - builtins mapping via `Builtins::getExtInstEnum` to the 20 16/32-bit-only `GLSL.std.450` ops above (covering `radians`, `degrees`, `sin..powr`, and `acospi..atan2pi`), and
  - `ReplaceableBuiltins` math lowerings that expand to them (`exp10`, `expm1`, `log10`, `log1p`, `pown`, `cospi`, `sinpi`, `tanpi`, `sincos`).
- Guard both body deletion (`have_native_impl`) and the `--use-native-builtins` unsupported-builtin error with `!keep_libclc_body`, leaving `float` native math and 64-bit native-capable GLSL/IR builtins (`sqrt`, `rsqrt`, `floor`, `ceil`, `trunc`, `rint`, `fma`, `fmin`, `fmax`, `mix`, `step`, `smoothstep`, `sign`, `ldexp`, `frexp`, `fract`, `length`, `distance`, `normalize`, `cross`, etc.) untouched (while FP64 `degrees` / `radians` lower to `FMul` via `libclc` / `ReplaceOpenCLBuiltinPass`).
- Add `test/double_operators.cl` covering scalar and vector `double` arithmetic, negation, comparisons, and ternary selection (default and `-vec3-to-vec4`).
- Add `test/NativeBuiltins/MathBuiltins/double_native_math.cl`, `double_mixed_float.cl` (capturing `fp64_double`, `fp64_v3double` where `OpTypeVector <double> 3` is emitted, and `fp64_v4double`), and `double_native_capable.cl`.

## Testing

- Verified `lit.py --filter="(NativeBuiltins|double_operators|double_degrees_radians)"` passes `195/195` tests on both `-arch=spirv32` and `-arch=spirv64` (`3,788` unrelated tests excluded), including `--cl-native-math`, `--use-native-builtins`, and `-vec3-to-vec4` with `spirv-val --target-env vulkan1.0`.
rjodinchr pushed a commit that referenced this pull request Nov 20, 2026
…ocs (#1753)

Ref #321.

Series follow-up PR (4/4) for #321 following #1750, #1751, and #1752
(remaining pre-existing FP64 edge cases are tracked in #321).

## Summary

Keep `libclc` software implementations for FP64 math builtins that lack
64-bit `GLSL.std.450` support in Vulkan SPIR-V under `--cl-native-math`
/ `--use-native-builtins`, add dedicated `double` operator tests, and
remove the stale incomplete-FP64 note from `docs/OpenCLCOnVulkan.md`.

## Problem

In SPIR-V `GLSL.std.450`, angle-conversion, transcendental, and
power/logarithmic instructions (`Radians`, `Degrees`, `Acos`, `Acosh`,
`Asin`, `Asinh`, `Atan`, `Atanh`, `Atan2`, `Sin`, `Sinh`, `Cos`, `Cosh`,
`Tan`, `Tanh`, `Exp`, `Exp2`, `Log`, `Log2`, `Pow`) only support 16-bit
and 32-bit floats. Under `--cl-native-math` or `--use-native-builtins`,
`NativeMathPass` deleted the `libclc` bodies of `double` math builtins
regardless of type, either emitting invalid 64-bit `GLSL.std.450`
instructions (`spirv-val` failure) or lowering via
`ReplaceOpenCLBuiltinPass` into unlowered `llvm.sincos` (`sincos`,
`tanpi`), which also broke transitive `libclc` callers such as `erf`,
`erfc`, `lgamma`, `lgamma_r`, `tgamma`, and `rootn` (and relied on
downstream `ReplaceOpenCLBuiltinPass::replaceDegreesOrRadians` for FP64
`degrees` / `radians`). In addition, the `64-Bit Floating-Point Types`
documentation still carried the note pointing to issue 321, and there
was no standalone `double` operator lit test.

## Change

- In `lib/NativeMathPass.cpp`, add `is_unsupported_fp64_glsl_op` and
`keep_fp64_libclc_body` to retain `libclc` bodies (`!F.isDeclaration()
&& F.getReturnType()->getScalarType()->isDoubleTy()`) for:
- builtins mapping via `Builtins::getExtInstEnum` to the 20
16/32-bit-only `GLSL.std.450` ops above (covering `radians`, `degrees`,
`sin..powr`, and `acospi..atan2pi`), and
- `ReplaceableBuiltins` math lowerings that expand to them (`exp10`,
`expm1`, `log10`, `log1p`, `pown`, `cospi`, `sinpi`, `tanpi`, `sincos`).
- Guard both body deletion (`have_native_impl`) and the
`--use-native-builtins` unsupported-builtin error with
`!keep_libclc_body`, leaving `float` native math and 64-bit
native-capable GLSL/IR builtins (`sqrt`, `rsqrt`, `floor`, `ceil`,
`trunc`, `rint`, `fma`, `fmin`, `fmax`, `mix`, `step`, `smoothstep`,
`sign`, `ldexp`, `frexp`, `fract`, `length`, `distance`, `normalize`,
`cross`, etc.) untouched (while FP64 `degrees` / `radians` lower to
`FMul` via `libclc` / `ReplaceOpenCLBuiltinPass`).
- Add `test/double_operators.cl` covering scalar and vector `double`
arithmetic, negation, comparisons, and ternary selection (default and
`-vec3-to-vec4`).
- Add `test/NativeBuiltins/MathBuiltins/double_native_math.cl`,
`double_mixed_float.cl` (capturing `fp64_double`, `fp64_v3double` where
`OpTypeVector <double> 3` is emitted, and `fp64_v4double`), and
`double_native_capable.cl`.
- Remove the obsolete incomplete-FP64 note referencing issue 321 in
`docs/OpenCLCOnVulkan.md`.

## Testing

- Verified `lit.py
--filter="(NativeBuiltins|double_operators|double_degrees_radians)"`
passes `195/195` tests on both `-arch=spirv32` and `-arch=spirv64`
(`3,788` unrelated tests excluded), including `--cl-native-math`,
`--use-native-builtins`, and `-vec3-to-vec4` with `spirv-val
--target-env vulkan1.0`.
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.

3 participants