-
Notifications
You must be signed in to change notification settings - Fork 882
Fix #8598: don't emit *.with.overflow intrinsics for DXIL #8600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
damyanp
wants to merge
2
commits into
microsoft:main
Choose a base branch
from
damyanp:damyanp/fix-8598-umul-overflow
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
tools/clang/test/DXC/Passes/InstructionCombining/instcombine-no-sadd-overflow-dxil.ll
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| ; RUN: %dxopt %s -instcombine -S | FileCheck %s | ||
|
|
||
| ; Regression test for https://github.com/microsoft/DirectXShaderCompiler/issues/8598 | ||
| ; | ||
| ; InstCombine used to fold this signed add overflow-check idiom into | ||
| ; llvm.sadd.with.overflow, which is not a legal DXIL intrinsic. For DXIL the | ||
| ; add/compare must be left alone. | ||
|
|
||
| target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64" | ||
| target triple = "dxil-ms-dx" | ||
|
|
||
| ; CHECK-LABEL: define i1 @test_sadd | ||
| ; CHECK-NOT: sadd.with.overflow | ||
| ; CHECK-NOT: extractvalue | ||
| ; CHECK: add {{(nsw )?}}i32 | ||
| ; CHECK: icmp ugt i32 | ||
| define i1 @test_sadd(i8 %a8, i8 %b8) { | ||
| %a = sext i8 %a8 to i32 | ||
| %b = sext i8 %b8 to i32 | ||
| %add = add i32 %a, %b | ||
| %addcst = add i32 %add, 128 | ||
| %cmp = icmp ugt i32 %addcst, 255 | ||
| ret i1 %cmp | ||
| } |
23 changes: 23 additions & 0 deletions
23
tools/clang/test/DXC/Passes/InstructionCombining/instcombine-no-umul-overflow-dxil.ll
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ; RUN: %dxopt %s -instcombine -S | FileCheck %s | ||
|
|
||
| ; Regression test for https://github.com/microsoft/DirectXShaderCompiler/issues/8598 | ||
| ; | ||
| ; InstCombine used to fold the "widened multiply compared against UINT_MAX" | ||
| ; idiom into llvm.umul.with.overflow, which is not a legal DXIL intrinsic and | ||
| ; failed validation. For DXIL the multiply/compare must be left alone. | ||
|
|
||
| target datalayout = "e-m:e-p:32:32-i1:32-i8:32-i16:32-i32:32-i64:64-f16:32-f32:32-f64:64-n8:16:32:64" | ||
| target triple = "dxil-ms-dx" | ||
|
|
||
| ; CHECK-LABEL: define i1 @test | ||
| ; CHECK-NOT: umul.with.overflow | ||
| ; CHECK-NOT: extractvalue | ||
| ; CHECK: mul {{(nuw )?}}i64 %xw, %yw | ||
| ; CHECK: icmp ugt i64 | ||
| define i1 @test(i32 %x, i32 %y) { | ||
| %xw = zext i32 %x to i64 | ||
| %yw = zext i32 %y to i64 | ||
| %mul = mul i64 %xw, %yw | ||
| %cmp = icmp ugt i64 %mul, 4294967295 | ||
| ret i1 %cmp | ||
| } |
23 changes: 23 additions & 0 deletions
23
tools/clang/test/HLSLFileCheck/hlsl/intrinsics/mul/mul_uint64_overflow_check.hlsl
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // RUN: %dxc -E main -T cs_6_0 %s | FileCheck %s | ||
|
|
||
| // Regression test for https://github.com/microsoft/DirectXShaderCompiler/issues/8598 | ||
| // | ||
| // The 32x32->64 bit multiply overflow check below used to be folded by | ||
| // InstCombine into llvm.umul.with.overflow.i32, an intrinsic that is not legal | ||
| // in DXIL and failed validation with optimizations enabled. Make sure it | ||
| // compiles and validates, keeping a plain 64-bit multiply. | ||
|
|
||
| // CHECK-NOT: umul.with.overflow | ||
| // CHECK: mul nuw i64 | ||
|
|
||
| RWStructuredBuffer<uint> buf : register(u0); | ||
|
|
||
| [numthreads(1, 1, 1)] | ||
| void main() | ||
| { | ||
| uint x = buf[0]; | ||
| uint y = buf[1]; | ||
| if (((uint64_t)x) * ((uint64_t)y) > 0xffffffffull) { | ||
| buf[2] = 1; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.