<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/152348>152348</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[DirectX] Select of two different RawBuffer can not easily be reduced to a callInst.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:DirectX
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
farzonl
</td>
</tr>
</table>
<pre>
This bug is very similar to [#140819](https://github.com/llvm/llvm-project/issues/140819)
However instead of an alloca store like pattern we have two different RawBuffer determined via a select.
## Possible Solution
What we might want to do here is replace the select with a branch and then create two calls for each RawBuffer
## Assert location
```gdb
frame #4: 0x00000001003b7430 clang-dxc`(anonymous namespace)::OpLowerer::lowerIntrinsics() [inlined] decltype(auto) llvm::cast<llvm::CallInst, llvm::Value>(Val=0x000060f00000a3c0) at Casting.h:578:3 [opt]
575
576 template <typename To, typename From>
577 [[nodiscard]] inline decltype(auto) cast(From *Val) {
-> 578 assert(isa<To>(Val) && "cast<Ty>() argument of incompatible type!");
579 return CastInfo<To, From *>::doCast(Val);
580 }
581
```
Like before the issue is we were expecting a CallInst
```gdb
frame #5: 0x00000001003b73e8 clang-dxc`(anonymous namespace)::OpLowerer::lowerIntrinsics() at DXILOpLowering.cpp:177:23 [opt]
174 }
175 // Otherwise, we're the second handle in a pair. Forward the arguments and
176 // remove the (second) cast.
-> 177 CallInst *Def = cast<CallInst>(Cast->getOperand(0));
178 assert(Def->getIntrinsicID() == Intrinsic::dx_resource_casthandle &&
179 "Unbalanced pair of temporary handle casts");
180 Cast->replaceAllUsesWith(Def->getOperand(0));
```
Crashing instruction:
```llvm
%. = select i1 %cmp14.not.i, target("dx.RawBuffer", half, 1, 0) %15, target("dx.RawBuffer", half, 1, 0) %11
```
```gdb
clang-dxc: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 22.0.0git (git@github.com:llvm/llvm-project.git 6d25d1d5508b7ba9aca77188a175d0a6348c581f)
Target: dxilv1.2-unknown-shadermodel6.2-compute
Thread model: posix
InstalledDir: /llvm_rel_with_deb_info/bin
Build config: +assertions, +asan
Cause instances: 60
Cause:
0. Program arguments: /llvm_rel_with_deb_info/bin/clang-dxc ../DirectML/Product/Shaders/Generated/Quantize_256_4_float16_native_accum32_int4_packed32.hlsl -E CSMain -T cs_6_2 -enable-16bit-types -O3 -D DXC_COMPILER=1 -D __SHADER_TARGET_MAJOR=6 -D __SHADER_TARGET_MINOR=2 -Vd -I ../DirectML/Product/Shaders/ -Fo ClangDML/tools/validation/Quantize_256_4_float16_native_accum32_int4_packed32.dat
1. <eof> parser at end of file
2. Code generation
3. Running pass 'DXIL Embedder' on module '../DirectML/Product/Shaders/Generated/Quantize_256_4_float16_native_accum32_int4_packed32.hlsl'.
----------------------------------------
============================================================
Stack Traces:
#0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (llvm_rel_with_deb_info/bin/clang-21+)
#1 llvm::sys::CleanupOnSignal(unsigned long) (llvm_rel_with_deb_info/bin/clang-21+)
#2 CrashRecoverySignalHandler(int) (llvm_rel_with_deb_info/bin/clang-21+)
#3 (/usr/lib/system/libsystem_platform.dylib+)
#4 (/usr/lib/system/libsystem_pthread.dylib+)
#5 (/usr/lib/system/libsystem_c.dylib+)
#6 (/usr/lib/system/libsystem_c.dylib+)
#7 (anonymous namespace)::OpLowerer::lowerIntrinsics() (/llvm_rel_with_deb_info/bin/clang-21+)
#8 (anonymous namespace)::DXILOpLoweringLegacy::runOnModule(llvm::Module&) (/llvm_rel_with_deb_info/bin/clang-21+)
#9 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/llvm_rel_with_deb_info/bin/clang-21+)
#10 clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::__1::unique_ptr<llvm::raw_pwrite_stream, std::__1::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/llvm_rel_with_deb_info/bin/clang-21+)
#11 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (llvm_rel_with_deb_info/bin/clang-21+)
#12 clang::ParseAST(clang::Sema&, bool, bool) (lvm_rel_with_deb_info/bin/clang-21+)
#13 clang::CodeGenAction::ExecuteAction() (llvm_rel_with_deb_info/bin/clang-21+)
#14 clang::FrontendAction::Execute() (/llvm_rel_with_deb_info/bin/clang-21+)
#15 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/llvm_rel_with_deb_info/bin/clang-21+)
#16 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/llvm_rel_with_deb_info/bin/clang-21+)
#17 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/llvm_rel_with_deb_info/bin/clang-21+)
#18 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) (/llvm_rel_with_deb_info/bin/clang-21+)
#19 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const::$_0>(long) (/llvm_rel_with_deb_info/bin/clang-21+)
#20 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/llvm_rel_with_deb_info/bin/clang-21+)
#21 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::__1::optional<llvm::StringRef>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>*, bool*) const (/llvm_rel_with_deb_info/bin/clang-21+)
#22 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/llvm_rel_with_deb_info/bin/clang-21+)
#23 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&, bool) const (/llvm_rel_with_deb_info/bin/clang-21+)
#24 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::__1::pair<int, clang::driver::Command const*>>&) (/llvm_rel_with_deb_info/bin/clang-21+)
#25 clang_main(int, char**, llvm::ToolContext const&) (/llvm_rel_with_deb_info/bin/clang-21+)
#26 main (/llvm_rel_with_deb_info/bin/clang-21+)
#27
clang-dxc: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 22.0.0git (git@github.com:llvm/llvm-project.git 6d25d1d5508b7ba9aca77188a175d0a6348c581f)
Target: dxilv1.2-unknown-shadermodel6.2-compute
Thread model: posix
InstalledDir: /llvm_rel_with_deb_info/bin
Build config: +assertions, +asan
Cause instances: 2
Cause:
0. Program arguments: /llvm_rel_with_deb_info/bin/clang-dxc ../DirectML/Product/Shaders/Generated/RNNOverwrite_16.hlsl -E CSMain -T cs_6_2 -enable-16bit-types -O3 -D DXC_COMPILER=1 -D __SHADER_TARGET_MAJOR=6 -D __SHADER_TARGET_MINOR=2 -Vd -I ../DirectML/Product/Shaders/ -Fo /ClangDML/tools/validation/RNNOverwrite_16.dat
1. <eof> parser at end of file
2. Code generation
3. Running pass 'DXIL Op Lowering' on module '../DirectML/Product/Shaders/Generated/RNNOverwrite_16.hlsl'.
----------------------------------------
============================================================
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsWt1y47aSfhr4pksqEhQl-cIXNGUlTs3EXtuZkzsWRDYl7ICAFgBl-zz9VoPUn0eezBnN2U3qROWyJQLo36-_BmAJ5-RSI16x9JqlswvR-pWxV7Ww_zRaXSxM9Xr1tJIOFu0SpIMN2ldwspFKWPAGaBlP4lE0jS9ZOmN8uvJ-7ViSMT5nfL6UftUuhqVpGJ8rtdn-Gayt-W8sPeNz6VyLjvF5L4Vfsij72TzjBi1I7TyKCkwNQoNQypQCnDcWQcnPCGvhPVoNzwgrsUHwzwYqWddoUXt4EM_XLX2ACj3aRmqsYCMFCHCosPRDFmX0wxPGE7g3zsmFQng0qvXSaBZl_1gJT9IbuV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