Expand llvm.{u,s}mul.with.overflow before SPIR-V emission - #1395
Open
pvelesko wants to merge 2 commits into
Open
Expand llvm.{u,s}mul.with.overflow before SPIR-V emission#1395pvelesko wants to merge 2 commits into
pvelesko wants to merge 2 commits into
Conversation
pvelesko
force-pushed
the
2026-07-29-github-1391-umul-overflow
branch
from
July 31, 2026 03:05
4e20bc8 to
353a165
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1391
Expands
llvm.umul.with.overflowandllvm.smul.with.overflowinto plain integer arithmetic in the post-link pass pipeline, so the construct never reaches SPIR-V.Without this, clang emits
llvm.umul.with.overflow.i64for a device-sidenew T[n]or__builtin_mul_overflow, the SPIR-V producer turns it into aspirv.llvm_umul_with_overflow_i64helper, and the consumer maps that back onto the intrinsic, renames the declaration toold_llvm.umul.with.overflow.i64and leaves it undefined. Since chipStar puts all device code of a binary into one module, the whole program stops working.Before and after on Aurora PVC (Intel Data Center GPU Max 1550), Level Zero, LLVM 22.1.3 with the in-tree SPIR-V backend, running the new regression test:
Counting
umul_with_overflowin the extracted SPIR-V of the same source goes from 7 to 0.The overflow predicate uses a division rather than a 128-bit multiply, since i128 is not portable across the SPIR-V consumers chipStar targets. These intrinsics come from allocation-size checks, so they are not hot. The signed case splits out
a == -1instead of folding it into the division, becausesdiv INT_MIN, -1is itself undefined.The regression test uses
__builtin_mul_overflowrather thannew T[n], so that it exercises the intrinsic without also depending on the device heap, which has a separate problem.