Skip to content

Commit

Permalink
sroa: Fix accidentally dropped condition (#50555)
Browse files Browse the repository at this point in the history
Fixes the issue noted in [1] (#50522) and
adds a test to make sure that it doesn't regress.

[1]
9b73611#r121641452
  • Loading branch information
aviatesk authored Jul 15, 2023
2 parents 7735556 + e464218 commit 99e2604
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ function sroa_pass!(ir::IRCode, inlining::Union{Nothing,InliningState}=nothing)
struct_typ = widenconst(argextype(val, compact))
struct_argtyp = argument_datatype(struct_typ)
if struct_argtyp === nothing
if isa(struct_typ, Union)
if isa(struct_typ, Union) && is_isdefined
lift_comparison!(isdefined, compact, idx, stmt, lifting_cache, 𝕃ₒ)
end
continue
Expand Down
17 changes: 17 additions & 0 deletions test/compiler/irpasses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1421,3 +1421,20 @@ let src = code_typed1(sroaunswitchunionstruct1, Tuple{Bool, Int, Float64})
end
@test sroaunswitchunionstruct2(true, 1, 1.0) === 1
@test sroaunswitchunionstruct2(false, 1, 1.0) === 1.0

# Test SROA of union into getfield
struct SingleFieldStruct1
x::Int
end
struct SingleFieldStruct2
x::Int
end
function foo(b, x)
if b
f = SingleFieldStruct1(x)
else
f = SingleFieldStruct2(x)
end
getfield(f, :x) + 1
end
@test foo(true, 1) == 2

2 comments on commit 99e2604

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.

Please sign in to comment.