Skip to content

[HLSL][clang] Move hlsl_wave_get_lane_index to EmitHLSLBuiltinExpr #87131

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

Merged
merged 1 commit into from
Mar 30, 2024

Conversation

marcauberer
Copy link
Member

Resolves #87109

@marcauberer marcauberer requested a review from farzonl March 30, 2024 00:54
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:codegen IR generation bugs: mangling, exceptions, etc. labels Mar 30, 2024
@llvmbot
Copy link
Member

llvmbot commented Mar 30, 2024

@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-clang-codegen

Author: Marc Auberer (marcauberer)

Changes

Resolves #87109


Full diff: https://github.com/llvm/llvm-project/pull/87131.diff

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGBuiltin.cpp (+8-10)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 287e763bad82dd..96ae16ba94c349 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5892,16 +5892,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
             Name),
         {NDRange, Kernel, Block}));
   }
-
-  case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
-    auto *CI = EmitRuntimeCall(CGM.CreateRuntimeFunction(
-        llvm::FunctionType::get(IntTy, {}, false), "__hlsl_wave_get_lane_index",
-        {}, false, true));
-    if (getTarget().getTriple().isSPIRVLogical())
-      CI = dyn_cast<CallInst>(addControlledConvergenceToken(CI));
-    return RValue::get(CI);
-  }
-
   case Builtin::BI__builtin_store_half:
   case Builtin::BI__builtin_store_halff: {
     Value *Val = EmitScalarExpr(E->getArg(0));
@@ -18317,6 +18307,14 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
         /*ReturnType=*/Op0->getType(), Intrinsic::dx_rsqrt,
         ArrayRef<Value *>{Op0}, nullptr, "dx.rsqrt");
   }
+  case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
+    auto *CI = EmitRuntimeCall(CGM.CreateRuntimeFunction(
+        llvm::FunctionType::get(IntTy, {}, false), "__hlsl_wave_get_lane_index",
+        {}, false, true));
+    if (getTarget().getTriple().isSPIRVLogical())
+      CI = dyn_cast<CallInst>(addControlledConvergenceToken(CI));
+    return RValue::get(CI);
+  }
   }
   return nullptr;
 }

@llvmbot
Copy link
Member

llvmbot commented Mar 30, 2024

@llvm/pr-subscribers-clang

Author: Marc Auberer (marcauberer)

Changes

Resolves #87109


Full diff: https://github.com/llvm/llvm-project/pull/87131.diff

1 Files Affected:

  • (modified) clang/lib/CodeGen/CGBuiltin.cpp (+8-10)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 287e763bad82dd..96ae16ba94c349 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5892,16 +5892,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
             Name),
         {NDRange, Kernel, Block}));
   }
-
-  case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
-    auto *CI = EmitRuntimeCall(CGM.CreateRuntimeFunction(
-        llvm::FunctionType::get(IntTy, {}, false), "__hlsl_wave_get_lane_index",
-        {}, false, true));
-    if (getTarget().getTriple().isSPIRVLogical())
-      CI = dyn_cast<CallInst>(addControlledConvergenceToken(CI));
-    return RValue::get(CI);
-  }
-
   case Builtin::BI__builtin_store_half:
   case Builtin::BI__builtin_store_halff: {
     Value *Val = EmitScalarExpr(E->getArg(0));
@@ -18317,6 +18307,14 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
         /*ReturnType=*/Op0->getType(), Intrinsic::dx_rsqrt,
         ArrayRef<Value *>{Op0}, nullptr, "dx.rsqrt");
   }
+  case Builtin::BI__builtin_hlsl_wave_get_lane_index: {
+    auto *CI = EmitRuntimeCall(CGM.CreateRuntimeFunction(
+        llvm::FunctionType::get(IntTy, {}, false), "__hlsl_wave_get_lane_index",
+        {}, false, true));
+    if (getTarget().getTriple().isSPIRVLogical())
+      CI = dyn_cast<CallInst>(addControlledConvergenceToken(CI));
+    return RValue::get(CI);
+  }
   }
   return nullptr;
 }

@marcauberer marcauberer marked this pull request as draft March 30, 2024 01:01
@marcauberer marcauberer force-pushed the clang/move-hlsl-builtin branch from 68d1215 to 283fe4e Compare March 30, 2024 01:27
@marcauberer marcauberer changed the title [Clang] Move hlsl_wave_get_lane_index to EmitHLSLBuiltinExpr [clang][HLSL] Move hlsl_wave_get_lane_index to EmitHLSLBuiltinExpr Mar 30, 2024
@marcauberer marcauberer force-pushed the clang/move-hlsl-builtin branch from 283fe4e to b275a7b Compare March 30, 2024 16:15
@marcauberer marcauberer marked this pull request as ready for review March 30, 2024 16:15
@farzonl
Copy link
Member

farzonl commented Mar 30, 2024

Hi @marcauberer The change looks good. I'm 99% sure this won't have an effect on the SPIRV backend, however there is still that 1% chance it does.

The tests I want to check landed in this PR
https://github.com/llvm/llvm-project/pull/85979/files

For convenience this is what you can pass to llvm-lit:

  • llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveGetLaneIndex.ll (really this one is the one im concerned about)
  • llvm/test/CodeGen/SPIRV/scfg-add-pre-headers.ll
  • llvm/test/CodeGen/SPIRV/transcoding/spirv-private-array-initialization.ll

Since you aren't changing anything in the SPIRV backend the github action didn't trigger. So if you could do one of two things after I approve, I would appreciate it,

Option 1: build spirv backend and test the above test cases
Should be a straight forward build

cmake -B <spirv-debug-build-dir> -G Ninja -S llvm -DLLVM_ENABLE_PROJECTS="llvm;clang" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=SPIRV -DLLVM_INCLUDE_SPIRV_TOOLS_TESTS=ON

Option 2: watch or trigger the SPIR_V Test github actions
https://github.com/llvm/llvm-project/actions/workflows/spirv-tests.yml
make sure the tests pass if they don't and it is one of the tests listed above you might have to revert your change.

@farzonl
Copy link
Member

farzonl commented Mar 30, 2024

minor nit pick, you don't have to do this one: In the title could you make the HLSL prefix first. It helps with some bookeeping we are doing.

@farzonl farzonl added the HLSL HLSL Language Support label Mar 30, 2024
@marcauberer marcauberer changed the title [clang][HLSL] Move hlsl_wave_get_lane_index to EmitHLSLBuiltinExpr [HLSL][clang] Move hlsl_wave_get_lane_index to EmitHLSLBuiltinExpr Mar 30, 2024
@marcauberer
Copy link
Member Author

@farzonl All three tests pass 👍🏽

$ ./bin/llvm-lit ../llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveGetLaneIndex.ll ../llvm/test/CodeGen/SPIRV/scfg-add-pre-headers.ll ../llvm/test/CodeGen/SPIRV/transcoding/spirv-private-array-initialization.ll
-- Testing: 3 tests, 3 workers --
PASS: LLVM :: CodeGen/SPIRV/scfg-add-pre-headers.ll (1 of 3)
PASS: LLVM :: CodeGen/SPIRV/transcoding/spirv-private-array-initialization.ll (2 of 3)
PASS: LLVM :: CodeGen/SPIRV/hlsl-intrinsics/WaveGetLaneIndex.ll (3 of 3)

Testing Time: 0.04s

Total Discovered Tests: 3
  Passed: 3 (100.00%)

@marcauberer marcauberer merged commit 3c8ede9 into llvm:main Mar 30, 2024
@marcauberer marcauberer deleted the clang/move-hlsl-builtin branch March 30, 2024 20:34
@marcauberer
Copy link
Member Author

Workflow run also succeeded: https://github.com/llvm/llvm-project/actions/runs/8493247308

@Keenuts
Copy link
Contributor

Keenuts commented Apr 2, 2024

Hi! Thanks @farzonl and @marcauberer for making sure SPIR-V backend didn't break, really appreciate it! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang Clang issues not falling into any other category HLSL HLSL Language Support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move __builtin_hlsl_wave_get_lane_index to EmitHLSLBuiltinExpr
4 participants