Skip to content

[SimplifyCFG] Fix illegal-width bitmap from switch lookup table - #8444

Merged
Damyan Pepper (damyanp) merged 5 commits into
microsoft:mainfrom
damyanp:8421
May 13, 2026
Merged

Damyan Pepper (damyanp) merged 5 commits into
microsoft:mainfrom
damyanp:8421

Conversation

@damyanp

@damyanp Damyan Pepper (damyanp) commented May 12, 2026 •

Copy link
Copy Markdown
Member

SwitchLookupTable built bitmap APInts of width TableSize * ResultBitWidth, producing non-standard integer widths (i9, i17, i26, i33, i40, ...) that DXIL validation rejects - DXIL only allows i1/i8/i16/i32/i64.

Round the bitmap width up to a legal width, and cap the optimization at 32 bits to avoid silently promoting to i64 (which would set the Int64Ops shader flag and add a 64-bit-integer capability requirement the source shader did not have). Wider tables fall back to the array path, or - for i1 results - preserve the original switch.

Closes #8421

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

…osoft#8421)

SwitchLookupTable built bitmap APInts of width `TableSize * ResultBitWidth`,
producing non-standard integer widths (i9, i17, i26, i33, i40, ...) that
DXIL validation rejects - DXIL only allows i1/i8/i16/i32/i64.

Round the bitmap width up to a legal width, and cap the optimization at
32 bits to avoid silently promoting to i64 (which would set the Int64Ops
shader flag and add a 64-bit-integer capability requirement the source
shader did not have). Wider tables fall back to the array path, or - for
i1 results - preserve the original switch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@llvm-beanz Chris B (llvm-beanz) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments, but I think I'm mostly okay with this.

Comment thread lib/Transforms/Utils/SimplifyCFG.cpp
Comment thread lib/Transforms/Utils/SimplifyCFG.cpp Outdated
Comment thread lib/Transforms/Utils/SimplifyCFG.cpp Outdated
@github-actions

github-actions Bot commented May 12, 2026 •

Copy link
Copy Markdown
Contributor

✅ With the latest revision this PR passed the C/C++ code formatter.

@bob80905 Joshua Batista (bob80905) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some questions with Alex Sepkowski (@alsepkow):

Comment thread lib/Transforms/Utils/SimplifyCFG.cpp

@bob80905 Joshua Batista (bob80905) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bogner Justin Bogner (bogner) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment on lines +3858 to +3859
// HLSL Change Begin: Round bitmap width up to size supported by DXIL (i16
// or i32)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the least invasive way to do this for DXC and so it's fine, but in clang we'll certainly want to leave the cleanup to widen to powers of two to a legalization step.

Comment on lines +3959 to +3960
// HLSL Change Begin: Cap at 32 bits so the bitmap stays in a DXIL-supported
// integer width and never promotes to i64 (which would set Int64Ops).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some argument that this should be the job of DataLayout::fitsInLegalInteger itself, but that's tricky since it's technically dependent on what integer sizes are already present. Hopefully in clang we can use the byte type for this transformation, which should allow us to avoid introducing new types unintentionally.

@damyanp
Damyan Pepper (damyanp) merged commit 3bb9bee into microsoft:main May 13, 2026
13 checks passed
@github-project-automation github-project-automation Bot moved this from New to Done in HLSL Roadmap May 13, 2026

@V-FEXrt Ashley Coleman (V-FEXrt) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (sorry kept getting pulled away from the review)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Compilation failure in DXC 1.10.2605.2 about invalid width i26 Integers

5 participants