-
Notifications
You must be signed in to change notification settings - Fork 165
Fix crash on partial-window accumulation into fixed-width vectors #2712
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dc5e688
Fix crash on partial-window accumulation into fixed-width vectors
minansys b11f08c
add the regression
minansys 5eea460
Update partial_vec_window.ll
minansys e8d9763
Merge branch 'main' into mixu/fix-partial-window
minansys 810ad27
Merge branch 'main' into mixu/fix-partial-window
minansys 9f5a52d
fix the comments
minansys c2037fa
update tests
minansys fef4dfb
Merge branch 'main' into mixu/fix-partial-window
minansys 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
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,39 @@ | ||
| ; RUN: %opt < %s %newLoadEnzyme -passes="enzyme,function(mem2reg,early-cse,sroa,instsimplify,%simplifycfg,adce)" -enzyme-preopt=false -S | FileCheck %s | ||
| ; Regression test: partial-window accumulation into a fixed vector (<2 x float>). | ||
| ; Previously asserted: "unhandled accumulate with partial sizes". | ||
|
|
||
| source_filename = "partial_vec_window" | ||
| target triple = "x86_64-pc-linux-gnu" | ||
|
|
||
| %ret2v = type { <2 x float>, <2 x float> } | ||
|
|
||
| define %ret2v @make(float %x) { | ||
| entry: | ||
| %v0 = insertelement <2 x float> zeroinitializer, float %x, i32 0 | ||
| %r0 = insertvalue %ret2v undef, <2 x float> %v0, 0 | ||
| %r1 = insertvalue %ret2v %r0, <2 x float> zeroinitializer, 1 | ||
| ret %ret2v %r1 | ||
| } | ||
|
|
||
| define float @tester(float %x) { | ||
| entry: | ||
| %call = call %ret2v @make(float %x) | ||
| %vec = extractvalue %ret2v %call, 0 | ||
|
|
||
| ; Force "partial" use: only the first 4 bytes of the <2 x float> | ||
| %tmp = alloca <2 x float>, align 8 | ||
| store <2 x float> %vec, <2 x float>* %tmp, align 8 | ||
| %fp = bitcast <2 x float>* %tmp to float* | ||
| %a = load float, float* %fp, align 4 | ||
|
|
||
| ret float %a | ||
| } | ||
|
|
||
| define float @test_derivative(float %x) { | ||
| entry: | ||
| %d = call float (float (float)*, ...) @__enzyme_autodiff(float (float)* @tester, float %x) | ||
| ret float %d | ||
| } | ||
|
|
||
| declare float @__enzyme_autodiff(float (float)*, ...) | ||
| ; CHECK: @diffetester | ||
|
minansys marked this conversation as resolved.
|
||
60 changes: 60 additions & 0 deletions
60
enzyme/test/Enzyme/ReverseModeVector/partial_vec_window.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,60 @@ | ||
| ; RUN: if [ %llvmver -lt 16 ]; then %opt < %s %loadEnzyme -enzyme -enzyme-preopt=false -mem2reg -simplifycfg -early-cse -S | FileCheck %s; fi | ||
| ; RUN: %opt < %s %newLoadEnzyme -passes="enzyme,function(mem2reg,%simplifycfg,early-cse)" -enzyme-preopt=false -S | FileCheck %s | ||
|
|
||
| ; Regression test: reverse vector mode handles partial-window accumulation into a fixed vector. | ||
|
|
||
| %struct.Gradients = type { [2 x float] } | ||
| %ret2v = type { <2 x float>, <2 x float> } | ||
|
|
||
| declare %struct.Gradients @__enzyme_autodiff(float (float)*, ...) | ||
|
|
||
| define %ret2v @make(float %x) { | ||
| entry: | ||
| %v0 = insertelement <2 x float> zeroinitializer, float %x, i32 0 | ||
| %r0 = insertvalue %ret2v undef, <2 x float> %v0, 0 | ||
| %r1 = insertvalue %ret2v %r0, <2 x float> zeroinitializer, 1 | ||
| ret %ret2v %r1 | ||
| } | ||
|
|
||
| define float @tester(float %x) { | ||
| entry: | ||
| %call = call %ret2v @make(float %x) | ||
| %vec = extractvalue %ret2v %call, 0 | ||
| %tmp = alloca <2 x float>, align 8 | ||
| store <2 x float> %vec, <2 x float>* %tmp, align 8 | ||
| %fp = bitcast <2 x float>* %tmp to float* | ||
| %a = load float, float* %fp, align 4 | ||
| ret float %a | ||
| } | ||
|
|
||
| define %struct.Gradients @test_derivative(float %x) { | ||
| entry: | ||
| %d = call %struct.Gradients (float (float)*, ...) @__enzyme_autodiff(float (float)* @tester, metadata !"enzyme_width", i64 2, float %x) | ||
| ret %struct.Gradients %d | ||
| } | ||
|
|
||
| ; CHECK-LABEL: define internal { [2 x float] } @diffe2tester(float %x, [2 x float] %differeturn) | ||
| ; CHECK: entry: | ||
| ; CHECK: %"vec'de" = alloca [2 x <2 x float>] | ||
| ; CHECK: %"call'de" = alloca [2 x %ret2v] | ||
| ; CHECK: %"x'de" = alloca [2 x float] | ||
| ; CHECK: %call_augmented = call [2 x %ret2v] @augmented_make(float %x) | ||
| ; CHECK: %"tmp'ipa" = alloca <2 x float> | ||
| ; CHECK: %"tmp'ipa1" = alloca <2 x float> | ||
| ; CHECK: %[[D0:.+]] = extractvalue [2 x float] %differeturn, 0 | ||
| ; CHECK: %[[L0:.+]] = load float, {{.*}}align 4{{.*}} | ||
| ; CHECK: %[[A0:.+]] = fadd fast float %[[L0]], %[[D0]] | ||
| ; CHECK: store float %[[A0]], {{.*}}align 4{{.*}} | ||
| ; CHECK: %[[D1:.+]] = extractvalue [2 x float] %differeturn, 1 | ||
| ; CHECK: %[[L1:.+]] = load float, {{.*}}align 4{{.*}} | ||
| ; CHECK: %[[A1:.+]] = fadd fast float %[[L1]], %[[D1]] | ||
| ; CHECK: store float %[[A1]], {{.*}}align 4{{.*}} | ||
| ; CHECK: %[[V0:.+]] = load <2 x float>, {{.*}}align 8{{.*}} | ||
| ; CHECK: %[[V1:.+]] = load <2 x float>, {{.*}}align 8{{.*}} | ||
| ; CHECK: %[[PACK:.+]] = load [2 x <2 x float>], {{.*}}align 8 | ||
| ; CHECK: %[[LANE0V:.+]] = extractvalue [2 x <2 x float>] %[[PACK]], 0 | ||
| ; CHECK: %[[LANE0:.+]] = extractelement <2 x float> %[[LANE0V]], i32 0 | ||
| ; CHECK: %[[LANE1V:.+]] = extractvalue [2 x <2 x float>] %[[PACK]], 1 | ||
| ; CHECK: %[[LANE1:.+]] = extractelement <2 x float> %[[LANE1V]], i32 0 | ||
| ; CHECK: %[[MAKE:.+]] = call { [2 x float] } @diffe2make(float %x) | ||
| ; CHECK: ret { [2 x float] } |
Oops, something went wrong.
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.