llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[SPIRV][DirectX][HLSL] Move `degrees` implementation to `hlsl_intrinsics.h`

Open farzonl opened this issue 4 months ago • 7 comments

  1. Remove Intrinsic::dx_degrees and Intrinsic::spv_degrees
  2. Remove BI__builtin_hlsl_degrees
  3. Remove BI__builtin_hlsl_degrees Sema checks from clang/lib/Sema/SemaHLSL.cpp
  4. Remove getDegreesIntrinsic from clang/lib/CodeGen/CGHLSLRuntime.h
  5. Remove emitting intrinsic from clang/lib/CodeGen/CGBuiltin.cpp
  6. Remove expandDegreesIntrinsic in llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp
  7. Implement degrees algorithm in hlsl_intrinsics.h via tablegen
  8. (Follow-up) add a pattern match for degrees as an InstCombine in llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp to be able to still emit the degrees GL extension.

farzonl avatar Jul 30 '26 18:07 farzonl

For any future implementer I would like the pattern matching to be a separate pr from the movement to the code from the backends to the HLSL header.

farzonl avatar Jul 30 '26 18:07 farzonl

Pattern matching will be a separate follow-up issue: https://github.com/llvm/llvm-project/issues/214882

kmpeng avatar Aug 07 '26 23:08 kmpeng

@llvm/issue-subscribers-clang-codegen

Author: Farzon Lotfi (farzonl)

1. Remove `Intrinsic::dx_degrees ` and `Intrinsic::spv_degrees` 2. Remove `BI__builtin_hlsl_degrees` 3. Remove `BI__builtin_hlsl_degrees` Sema checks from `clang/lib/Sema/SemaHLSL.cpp` 4. Remove `getDegreesIntrinsic` from `clang/lib/CodeGen/CGHLSLRuntime.h` 5. Remove emitting intrinsic from `clang/lib/CodeGen/CGBuiltin.cpp` 6. Remove `expandDegreesIntrinsic` in `llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp` 7. Implement degrees algorithm in `hlsl_intrinsics.h` via tablegen 8. (Follow-up) add a pattern match for degrees as an InstCombine in `llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp` to be able to still emit the degrees GL extension.

@llvm/issue-subscribers-clang-frontend

Author: Farzon Lotfi (farzonl)

1. Remove `Intrinsic::dx_degrees ` and `Intrinsic::spv_degrees` 2. Remove `BI__builtin_hlsl_degrees` 3. Remove `BI__builtin_hlsl_degrees` Sema checks from `clang/lib/Sema/SemaHLSL.cpp` 4. Remove `getDegreesIntrinsic` from `clang/lib/CodeGen/CGHLSLRuntime.h` 5. Remove emitting intrinsic from `clang/lib/CodeGen/CGBuiltin.cpp` 6. Remove `expandDegreesIntrinsic` in `llvm/lib/Target/DirectX/DXILIntrinsicExpansion.cpp` 7. Implement degrees algorithm in `hlsl_intrinsics.h` via tablegen 8. (Follow-up) add a pattern match for degrees as an InstCombine in `llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp` to be able to still emit the degrees GL extension.

4. For any future implementer I would like the pattern matching to be a separate pr from the movement to the code from the backends to the HLSL header.

But why? Like this you are forcing yourself to fight windmills in case if middle end changes the desired pattern. You are also inherently losing debug information as pattern matcher runs with -O0. If you have a target-specific instruction it's normal practice to expose it in IR via an intrinsic wiring up with the frontend via builtin.

MrSidims avatar Nov 02 '26 10:11 MrSidims

22. > 4. For any future implementer I would like the pattern matching to be a separate pr from the movement to the code from the backends to the HLSL header.

 But why? Like this you are forcing yourself to fight windmills in case if middle end changes the desired pattern. You are also inherently losing debug information as pattern matcher runs with -O0. If you have a target-specific instruction it's normal practice to expose it in IR via an intrinsic wiring up with the frontend via builtin.

We were using builtin. The feedback we recieved was not to I responded to you here about that feedback. https://github.com/llvm/llvm-project/pull/237935#discussion_r4445546546 This was the RFC: https://discourse.llvm.org/t/rfc-add-targetbuiltins-for-spirv-to-support-hlsl/83329

farzonl avatar Nov 02 '26 18:11 farzonl

 We were using builtin. The feedback we recieved was not to I responded to you here about that feedback. [#237935 (comment)](https://github.com/llvm/llvm-project/pull/237935#discussion_r4445546546) This was the RFC: https://discourse.llvm.org/t/rfc-add-targetbuiltins-for-spirv-to-support-hlsl/83329

Thank you, now I have the full context. I'll reply back in the PR's thread, when I come up with (probably) acceptable suggestions.

MrSidims avatar Nov 02 '26 18:11 MrSidims