microsoft / microsoft/DirectXShaderCompiler

HLSL loop optimization results in an unsupported i33 type

Open
#5,059 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug correctness dxil validation
Dominant language
C++
Stars
3.7k
Forks
900
Avg merge
2d 11h
Merged PRs (30d)
44

Description

Compiling i33.hlsl.txt with -T lib_6_3 i33.hlsl -Fc i33.dxil.txt shows a zext of i32 to i33. The DXIL spec only mentions support for integer types “i1, i8, i16, i32, i64”.

Relevant snippet from i33.dxil.txt:

  %8 = zext i32 %7 to i33
  %9 = add i32 %4, -2
  %10 = zext i32 %9 to i33
  %11 = mul i33 %8, %10
  %12 = lshr i33 %11, 1
  %13 = trunc i33 %12 to i32

Tested on December 2022 and October 2020 releases.

The i33 type is added by the Scalar Evolution pass - this is a standard LLVM pass that is used to optimize loop control expressions. Where possible it replaces the loop control expression with a constant or a simpler expression which replaces the loop, or at least reduces the number of iterations. The expression used is ((input - 1) * (input - 2)) / 2 and the extension to i33 is to allow for the possibility of the multiplication resulting in overflow - the division by 2 guarantees the final result fits in i32.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by compiling the linked i33.hlsl.txt with -T lib_6_3 i33.hlsl -Fc i33.dxil.txt and compare the generated i33.dxil.txt with the supported integer types listed in docs/DXIL.rst. Trace the Scalar Evolution loop optimization that produces the i33 zext, and consider the issue complete when valid DXIL no longer contains the unsupported i33 operations while preserving the loop result.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.