Fix #8598: don't emit *.with.overflow intrinsics for DXIL#8600
Open
damyanp wants to merge 2 commits into
Open
Conversation
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>
Contributor
You can test this locally with the following command:git-clang-format --diff 58539905da4f21b9c120b9d1946ee43840e0ac72 855a0c1d5e3fdf75e488eff9d705b2e5e769249b -- lib/Transforms/InstCombine/InstCombineCompares.cppView 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;
|
V-FEXrt
approved these changes
Jul 2, 2026
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.
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