<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/117273>117273</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [DirectX] DXIL Data Scalarization crash
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:DirectX
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          llvm-beanz
      </td>
    </tr>
</table>

<pre>
    The following shader to compute a mandelbrot set crashes the DXIL Data Scalarizer:

```hlsl
RWBuffer<float4> Tex;

const static float3 Palette[8] = {float3(0.0, 0.0, 0.0), float3(0.5, 0.5, 0.5),
 float3(1.0, 0.5, 0.5), float3(0.5, 1.0, 0.5),
 float3(0.5, 0.5, 1.0), float3(0.5, 1.0, 1.0),
                                  float3(1.0, 0.5, 1.0), float3(1.0, 1.0, 0.5)};

const static int Dimension = 4096;

[numthreads(1024, 1, 1)] void main(uint3 DID
 : SV_DispatchThreadID) {
  float scale = 1.5 / pow(2.0, 16.0 * abs(sin(0.25 / 16.0)));
  float2 offset = float2(-1.0, 0.0);
 uint2 Index =
      uint2(DID.x % Dimension, DID.x / Dimension + (Dimension * DID.y));
  uint2 DispatchSize = Dimension.xx;
  float X0 =
      scale * (2.0 * (float)Index.x / (float)DispatchSize.x - 1.5) + offset.x;
  float Y0 =
      scale * (2.0 * (float)Index.y / (float)DispatchSize.y - 1.0) + offset.y;

  // Implement Mandelbrot set
  float X = X0;
  float Y = Y0;
  uint Iteration = 0;
  uint MaxIteration = 2000;
  float XTmp = 0.0;
  bool Diverged = false;
 for (; Iteration < MaxIteration; ++Iteration) {
    if (X * X + Y * Y > 2000 * 2000) {
      Diverged = true;
      break;
    }
    XTmp = X * X - Y * Y + X0;
    Y = 2 * X * Y + Y0;
    X = XTmp;
 }

  float3 Color = float3(0, 0, 0);
  if (Diverged) {
    float Gradient = 1.0;
    float Smooth = log2(log2(X * X + Y * Y) / 2.0);
 float ColorIdx = sqrt((float)Iteration + 10.0 - Smooth) * Gradient;
 float LerpSize = frac(ColorIdx);
    LerpSize = LerpSize * LerpSize * (3.0 - 2.0 * LerpSize);
    int ColorIdx1 = (int)ColorIdx % 8;
    int ColorIdx2 = (ColorIdx1 + 1) % 8;
    Color = lerp(Palette[ColorIdx1], Palette[ColorIdx2], LerpSize.xxx);
  }

  Tex[DID.x] = float4(Color, 1.0);
}
```

Crash backtrace:

```
0.      Program arguments: C:\\Users\\cbieneman\\dev\\llvm-project\\llvm\\out\\build\\x64-Clang-Debug\\bin\\clang-dxc.exe -cc1 -triple dxilv1.0-unknown-shadermodel6.0-compute -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name Mandelbrot.hlsl -mrelocation-model static -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -debugger-tuning=gdb -fdebug-compilation-dir=C:\\Users\\cbieneman\\dev\\llvm-project\\llvm\\out\\build\\x64-Clang-Debug -fcoverage-compilation-dir=C:\\Users\\cbieneman\\dev\\llvm-project\\llvm\\out\\build\\x64-Clang-Debug -resource-dir C:\\Users\\cbieneman\\dev\\llvm-project\\llvm\\out\\build\\x64-Clang-Debug\\lib\\clang\\20 -O3 -ferror-limit 19 -fmessage-length=350 -O3 -finclude-default-header -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -vectorize-loops -vectorize-slp -o mandelbrot.yaml -x hlsl C:\\Users\\cbieneman\\dev\\hlsl-test-suite\\test\\Basic\\Inputs\\Mandelbrot.hlsl
1. <eof> parser at end of file
2.      Code generation
3. Running pass 'DXIL Data Scalarization' on module 'C:\Users\cbieneman\dev\hlsl-test-suite\test\Basic\Inputs\Mandelbrot.hlsl'.
Exception Code: 0xC0000005
 #0 0x00007ff735544409 llvm::Value::getValueID(void) const C:\Users\cbieneman\dev\llvm-project\llvm\include\llvm\IR\Value.h:533:0
 #1 0x00007ff73556dc13 llvm::ConstantExpr::classof(class llvm::Value const *) C:\Users\cbieneman\dev\llvm-project\llvm\include\llvm\IR\Constants.h:1385:0
 #2 0x00007ff7365085d3 llvm::isa_impl<class llvm::ConstantExpr, class llvm::User, void>::doit(class llvm::User const &) C:\Users\cbieneman\dev\llvm-project\llvm\include\llvm\Support\Casting.h:64:0
 #3 0x00007ff7367fd679 llvm::isa_impl_cl<class llvm::ConstantExpr, class llvm::User const *>::doit(class llvm::User const *) C:\Users\cbieneman\dev\llvm-project\llvm\include\llvm\Support\Casting.h:110:0
 #4 0x00007ff7367fd636 llvm::isa_impl_wrap<class llvm::ConstantExpr, class llvm::User const *, class llvm::User const *>::doit(class llvm::User const *const &) C:\Users\cbieneman\dev\llvm-project\llvm\include\llvm\Support\Casting.h:137:0
 #5 0x00007ff7367fd601 llvm::isa_impl_wrap<class llvm::ConstantExpr, class llvm::User const *const, class llvm::User const *>::doit(class llvm::User const *const &) C:\Users\cbieneman\dev\llvm-project\llvm\include\llvm\Support\Casting.h:127:0
 #6 0x00007ff7367fd5c3 llvm::CastIsPossible<class llvm::ConstantExpr, class llvm::User const *, void>::isPossible(class llvm::User const *const &) C:\Users\cbieneman\dev\llvm-project\llvm\include\llvm\Support\Casting.h:255:0
 #7 0x00007ff7367fd591 llvm::CastInfo<class llvm::ConstantExpr, class llvm::User *const, void>::isPossible(class llvm::User *const &) C:\Users\cbieneman\dev\llvm-project\llvm\include\llvm\Support\Casting.h:509:0
 #8 0x00007ff7367fc583 llvm::isa<class llvm::ConstantExpr, class llvm::User *>(class llvm::User *const &) C:\Users\cbieneman\dev\llvm-project\llvm\include\llvm\Support\Casting.h:549:0
 #9 0x00007ff7367fb947 findAndReplaceVectors C:\Users\cbieneman\dev\llvm-project\llvm\lib\Target\DirectX\DXILDataScalarization.cpp:248:0
#10 0x00007ff7367fbb68 DXILDataScalarizationLegacy::runOnModule(class llvm::Module &) C:\Users\cbieneman\dev\llvm-project\llvm\lib\Target\DirectX\DXILDataScalarization.cpp:284:0
#11 0x00007ff73594e646 `anonymous namespace'::MPPassManager::runOnModule C:\Users\cbieneman\dev\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:1521:0
#12 0x00007ff73594e10a llvm::legacy::PassManagerImpl::run(class llvm::Module &) C:\Users\cbieneman\dev\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:539:0
#13 0x00007ff735952de1 llvm::legacy::PassManager::run(class llvm::Module &) C:\Users\cbieneman\dev\llvm-project\llvm\lib\IR\LegacyPassManager.cpp:1648:0
#14 0x00007ff737667208 `anonymous namespace'::EmitAssemblyHelper::RunCodegenPipeline C:\Users\cbieneman\dev\llvm-project\clang\lib\CodeGen\BackendUtil.cpp:1197:0
#15 0x00007ff737660f2b `anonymous namespace'::EmitAssemblyHelper::EmitAssembly C:\Users\cbieneman\dev\llvm-project\clang\lib\CodeGen\BackendUtil.cpp:1221:0
#16 0x00007ff7376601ef clang::EmitBackendOutput(class clang::DiagnosticsEngine &, class clang::HeaderSearchOptions const &, class clang::CodeGenOptions const &, class clang::TargetOptions const &, class clang::LangOptions const &, class llvm::StringRef, class llvm::Module *, enum clang::BackendAction, class llvm::IntrusiveRefCntPtr<class llvm::vfs::FileSystem>, class std::unique_ptr<class llvm::raw_pwrite_stream, struct std::default_delete<class llvm::raw_pwrite_stream>>, class clang::BackendConsumer *) C:\Users\cbieneman\dev\llvm-project\clang\lib\CodeGen\BackendUtil.cpp:1386:0
#17 0x00007ff738031450 clang::BackendConsumer::HandleTranslationUnit(class clang::ASTContext &) C:\Users\cbieneman\dev\llvm-project\clang\lib\CodeGen\CodeGenAction.cpp:355:0
#18 0x00007ff73ade1e03 clang::ParseAST(class clang::Sema &, bool, bool) C:\Users\cbieneman\dev\llvm-project\clang\lib\Parse\ParseAST.cpp:191:0
#19 0x00007ff737d94987 clang::ASTFrontendAction::ExecuteAction(void) C:\Users\cbieneman\dev\llvm-project\clang\lib\Frontend\FrontendAction.cpp:1193:0
#20 0x00007ff738035a7a clang::CodeGenAction::ExecuteAction(void) C:\Users\cbieneman\dev\llvm-project\clang\lib\CodeGen\CodeGenAction.cpp:1140:0
#21 0x00007ff737d9434d clang::FrontendAction::Execute(void) C:\Users\cbieneman\dev\llvm-project\clang\lib\Frontend\FrontendAction.cpp:1081:0
#22 0x00007ff735fff094 clang::CompilerInstance::ExecuteAction(class clang::FrontendAction &) C:\Users\cbieneman\dev\llvm-project\clang\lib\Frontend\CompilerInstance.cpp:1065:0
#23 0x00007ff73611c5ab clang::ExecuteCompilerInvocation(class clang::CompilerInstance *) C:\Users\cbieneman\dev\llvm-project\clang\lib\FrontendTool\ExecuteCompilerInvocation.cpp:296:0
#24 0x00007ff735510fd1 cc1_main(class llvm::ArrayRef<char const *>, char const *, void *) C:\Users\cbieneman\dev\llvm-project\clang\tools\driver\cc1_main.cpp:285:0
#25 0x00007ff7355027db ExecuteCC1Tool C:\Users\cbieneman\dev\llvm-project\clang\tools\driver\driver.cpp:218:0
#26 0x00007ff7355014db clang_main(int, char **, struct llvm::ToolContext const &) C:\Users\cbieneman\dev\llvm-project\clang\tools\driver\driver.cpp:259:0
#27 0x00007ff735538f92 main C:\Users\cbieneman\dev\llvm-project\llvm\out\build\x64-Clang-Debug\tools\clang\tools\driver\clang-driver.cpp:17:0
#28 0x00007ff73f0def79 invoke_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:79:0
#29 0x00007ff73f0df0b2 __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#30 0x00007ff73f0df13e __scrt_common_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331:0
#31 0x00007ff73f0df15e mainCRTStartup D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:17:0
#32 0x00007ffb446bdbe7 (C:\WINDOWS\System32\KERNEL32.DLL+0x2dbe7)
#33 0x00007ffb4515fbec (C:\WINDOWS\SYSTEM32\ntdll.dll+0xdfbec)
```


</pre>
<img width="1px" height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