Skip to content
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

combine ifelse and select_value; improve ifelse t-func #27068

Merged
merged 2 commits into from
May 12, 2018
Merged

Conversation

JeffBezanson
Copy link
Member

No description provided.

@JeffBezanson JeffBezanson added the compiler:inference Type inference label May 10, 2018
@Keno
Copy link
Member

Keno commented May 11, 2018

Should address the same benchmarks that #26969 was supposed to.

@nanosoldier runbenchmarks(ALL, vs=":master")

@Keno Keno mentioned this pull request May 11, 2018
18 tasks
@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@JeffBezanson
Copy link
Member Author

Do we think this actually introduced allocations in the union benchmarks, or is something up with the benchmarks or the comparison data?

@Keno
Copy link
Member

Keno commented May 11, 2018

I was about to check.

@Keno
Copy link
Member

Keno commented May 11, 2018

Looks like something is broken with select_value codegen. It boxes the value in order to do the select:

  %26 = bitcast %jl_value_t addrspace(11)* %23 to float addrspace(11)*
  %27 = load float, float addrspace(11)* %26, align 4
  %28 = call %jl_value_t addrspace(10)* @jl_box_float32(float %27)
  %29 = select i1 %25, %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140374922305472 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)* %28
; Function +; {
; Location: float.jl:390
  %30 = bitcast %jl_value_t addrspace(10)* %29 to float addrspace(10)*
  %31 = load float, float addrspace(10)* %30, align 4
  %32 = fadd fast float %s.225, %31

I suspect you need to use the inferred return type in codegen to force an implicit convert of the arguments

@Keno
Copy link
Member

Keno commented May 11, 2018

I have a fix. Let me push it here.

@Keno Keno force-pushed the jb/ifelse branch 2 times, most recently from 598af2c to e77f2c7 Compare May 11, 2018 15:04
if (match.best_idx == (uint32_t)-1) {
match.best_idx = 0;
//jl_error("Unable to find compatible target in system image.");
}
Copy link
Member Author

Choose a reason for hiding this comment

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

?

Copy link
Member

Choose a reason for hiding this comment

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

whoops.

@Keno
Copy link
Member

Keno commented May 11, 2018

Fixed. That's what I get for coding before breakfast.

@nanosoldier runbenchmarks(ALL, vs = ":master")

tx = argtypes[3]
ty = argtypes[4]
if isa(fargs[3], Slot) && slot_id(cnd.var) == slot_id(fargs[3])
tx = typeintersect(tx, cnd.vtype)
Copy link
Member

Choose a reason for hiding this comment

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

just tx = cnd.vtype. it's already guaranteed to be a subtype of the old tx

end
if !isa(cnd, Conditional) && !(Bool ⊑ cnd)
elseif isa(cnd, Conditional)
# handled in abstract_call
Copy link
Member

Choose a reason for hiding this comment

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

it's not

@@ -3155,15 +3153,15 @@ static jl_cgval_t emit_call(jl_codectx_t &ctx, jl_expr_t *ex)
}

if (f.constant && jl_isa(f.constant, (jl_value_t*)jl_builtin_type)) {
if (f.constant == jl_builtin_ifelse && nargs == 4)
return emit_ifelse(ctx, argv[1], argv[2], argv[3], rt);
Copy link
Member

Choose a reason for hiding this comment

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

should go in emit_builtin_call with the others like it?

@@ -200,8 +200,11 @@ add_tfunc(Core.Intrinsics.select_value, 3, 3,
else
return Bottom
end
elseif isa(cnd, Conditional)
# handled in abstract_call
Copy link
Member

Choose a reason for hiding this comment

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

it's not fully handled there, so it can appear here too

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there anything further that can be done with Conditional here? Anyway I think it's helpful to have this comment so one knows where to look for the full behavior.

Copy link
Member

Choose a reason for hiding this comment

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

you can check whether the conditional is equivalent to a Const (i.e. that special case we added in).

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok. I say we do that later unless it's needed to meet our immediate goals.

Keno added a commit that referenced this pull request May 11, 2018
This is just the pinode insertion code from #26969, which together
with #27068, should hopefully cover the same benchmarks in a more
acceptable way.
@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

@Keno
Copy link
Member

Keno commented May 11, 2018

Performance looks good.

Fix ifelse codegen

Our return hint may be a concrete type, in which case we want to do the
implicit convert before we decide on a strategy for actually emitting
the select.
@JeffBezanson JeffBezanson merged commit 39cbbc2 into master May 12, 2018
@JeffBezanson JeffBezanson deleted the jb/ifelse branch May 12, 2018 19:18
@vchuravy vchuravy mentioned this pull request Aug 10, 2019
c42f added a commit that referenced this pull request Sep 2, 2020
TODO: This regresses some inference support for ifelse, likely undoing
some of the work from #27068 ("Combine `ifelse` and `select_value`;
improve `ifelse` t-func")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:inference Type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants