Skip to content

Commit

Permalink
some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 11, 2018
1 parent 5b6efe9 commit 832bfb7
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,9 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, Value **arg

static jl_cgval_t emit_ifelse(jl_codectx_t &ctx, jl_cgval_t c, jl_cgval_t x, jl_cgval_t y, jl_value_t *rt_hint)
{
Value *isfalse = emit_condition(ctx, c, "ifelse"); // emit the first argument
// emit X and Y arguments
jl_value_t *t1 = x.typ;
jl_value_t *t2 = y.typ;
// check the return value was valid
// handle cases where the condition is irrelevant based on type info
if (t1 == jl_bottom_type && t2 == jl_bottom_type)
return jl_cgval_t(); // undefined
if (t1 == jl_bottom_type)
Expand All @@ -795,23 +793,23 @@ static jl_cgval_t emit_ifelse(jl_codectx_t &ctx, jl_cgval_t c, jl_cgval_t x, jl_
return x;

if (t1 != t2) {
// type inference may know something we don't, in which case it may
// be illegal for us to convert to rt_hint. Check first if either
// of the types have empty intersection with the result type,
// in which case, we may use the other one.
if (jl_type_intersection(t1, rt_hint) == jl_bottom_type) {
return y;
} else if (jl_type_intersection(t2, rt_hint) == jl_bottom_type) {
return x;
}
// if they aren't the same type, consider using the expr type
// to instantiate a union-split optimization
x = convert_julia_type(ctx, x, rt_hint);
y = convert_julia_type(ctx, y, rt_hint);
t1 = x.typ;
t2 = y.typ;
// type inference may know something we don't, in which case it may
// be illegal for us to convert to rt_hint. Check first if either
// of the types have empty intersection with the result type,
// in which case, we may use the other one.
if (jl_type_intersection(t1, rt_hint) == jl_bottom_type)
return y;
else if (jl_type_intersection(t2, rt_hint) == jl_bottom_type)
return x;
// if they aren't the same type, consider using the expr type
// to instantiate a union-split optimization
x = convert_julia_type(ctx, x, rt_hint);
y = convert_julia_type(ctx, y, rt_hint);
t1 = x.typ;
t2 = y.typ;
}

Value *isfalse = emit_condition(ctx, c, "ifelse");

This comment has been minimized.

Copy link
@Keno

Keno May 11, 2018

Member

This is incorrect as long as the condition can have side effects. I also believe emit_condition does type checks, so this would create problems for something like a Union{Int, Bool}.

This comment has been minimized.

Copy link
@JeffBezanson

JeffBezanson May 11, 2018

Author Member

The code for the condition has already been emitted, but you're right about the type check.

This comment has been minimized.

Copy link
@JeffBezanson

JeffBezanson May 11, 2018

Author Member

emit_condition should probably be renamed something like to_condition or as_condition.

Value *ifelse_result;
bool isboxed;
Type *llt1 = julia_type_to_llvm(t1, &isboxed);
Expand Down

0 comments on commit 832bfb7

Please sign in to comment.