Skip to content

Fix #8598: don't emit *.with.overflow intrinsics for DXIL#8600

Open
damyanp wants to merge 2 commits into
microsoft:mainfrom
damyanp:damyanp/fix-8598-umul-overflow
Open

Fix #8598: don't emit *.with.overflow intrinsics for DXIL#8600
damyanp wants to merge 2 commits into
microsoft:mainfrom
damyanp:damyanp/fix-8598-umul-overflow

Conversation

@damyanp

@damyanp damyanp commented Jul 1, 2026

Copy link
Copy Markdown
Member

InstCombine folds the "widened multiply/add compared against a max value" overflow-check idioms into llvm.umul.with.overflow / llvm.sadd.with.overflow. These intrinsics (and the extractvalue of their result struct) are not legal in DXIL, so shaders using them failed validation once optimizations were on.

Guard ProcessUMulZExtIdiom and ProcessUGT_ADDCST_ADD to bail out for the DXIL target, mirroring the existing isDXIL() guard on bswap matching. The plain multiply/add and compare are kept, which is what DXIL wants anyway.

Adds .ll regression tests for both idioms plus an end-to-end HLSL test built from the issue repro.

Assisted-by: copilot
Fixes #8598

InstCombine folds the "widened multiply/add compared against a max value"
overflow-check idioms into llvm.umul.with.overflow / llvm.sadd.with.overflow.
These intrinsics (and the extractvalue of their result struct) are not legal
in DXIL, so shaders using them failed validation once optimizations were on.

Guard ProcessUMulZExtIdiom and ProcessUGT_ADDCST_ADD to bail out for the DXIL
target, mirroring the existing isDXIL() guard on bswap matching. The plain
multiply/add and compare are kept, which is what DXIL wants anyway.

Adds .ll regression tests for both idioms plus an end-to-end HLSL test built
from the issue repro.

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

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 58539905da4f21b9c120b9d1946ee43840e0ac72 855a0c1d5e3fdf75e488eff9d705b2e5e769249b -- lib/Transforms/InstCombine/InstCombineCompares.cpp
View the diff from clang-format here.
diff --git a/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 333db5f3..bc296ab5 100644
--- a/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -18,6 +18,7 @@
 #include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/Analysis/InstructionSimplify.h"
 #include "llvm/Analysis/MemoryBuiltins.h"
+#include "llvm/Analysis/TargetLibraryInfo.h"
 #include "llvm/IR/ConstantRange.h"
 #include "llvm/IR/DataLayout.h"
 #include "llvm/IR/GetElementPtrTypeIterator.h"
@@ -25,7 +26,6 @@
 #include "llvm/IR/PatternMatch.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
-#include "llvm/Analysis/TargetLibraryInfo.h"
 
 using namespace llvm;
 using namespace PatternMatch;
  • Check this box to apply formatting changes to this branch.

Comment thread lib/Transforms/InstCombine/InstCombineCompares.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

Validation error when optimizations are enabled: llvm.umul.with.overflow.i32 is not a DXIL function

2 participants