@@ -1193,19 +1193,34 @@ static jl_cgval_t emit_ifelse(jl_codectx_t &ctx, jl_cgval_t c, jl_cgval_t x, jl_
11931193 Value *x_tindex = x.TIndex ;
11941194 Value *y_tindex = y.TIndex ;
11951195 if (x_tindex || y_tindex) {
1196- if (!x.isghost )
1197- x = value_to_pointer (ctx, x);
1198- if (!y.isghost )
1199- y = value_to_pointer (ctx, y);
12001196 Value *x_vboxed = x.Vboxed ;
12011197 Value *y_vboxed = y.Vboxed ;
1202- Value *x_ptr = (x. isghost ? NULL : data_pointer (ctx, x)) ;
1203- Value *y_ptr = (y. isghost ? NULL : data_pointer (ctx, y)) ;
1204- MDNode *ifelse_tbaa;
1205- if (!x. isghost && x. constant )
1198+ Value *x_ptr = NULL ;
1199+ Value *y_ptr = NULL ;
1200+ if (!x. isghost && x. constant ) {
1201+ x_ptr = data_pointer (ctx, x);
12061202 x_vboxed = boxed (ctx, x);
1207- if (!y.isghost && y.constant )
1203+ } else if (!x.isghost && x.V != NULL ) {
1204+ x_ptr = maybe_decay_tracked (ctx, x.V );
1205+ }
1206+ if (!y.isghost && y.constant ) {
1207+ y_ptr = data_pointer (ctx, y);
12081208 y_vboxed = boxed (ctx, y);
1209+ } else if (!y.isghost && y.V != NULL ) {
1210+ y_ptr = maybe_decay_tracked (ctx, y.V );
1211+ }
1212+ auto nroots = std::max (x.inline_roots .size (), y.inline_roots .size ());
1213+ Value *Vnull = Constant::getNullValue (ctx.types ().T_prjlvalue );
1214+ SmallVector<Value *, 0 > ifelse_roots (nroots, Vnull);
1215+ for (size_t i = 0 ; i < nroots; i++) {
1216+ Value *x_root = Vnull, *y_root = Vnull;
1217+ if (i < x.inline_roots .size ())
1218+ x_root = x.inline_roots [i];
1219+ if (i < y.inline_roots .size ())
1220+ y_root = y.inline_roots [i];
1221+ ifelse_roots[i] = ctx.builder .CreateSelect (isfalse, y_root, x_root);
1222+ }
1223+ MDNode *ifelse_tbaa;
12091224 if (!x_ptr && !y_ptr) { // both ghost
12101225 ifelse_result = NULL ;
12111226 ifelse_tbaa = ctx.tbaa ().tbaa_stack ;
@@ -1269,7 +1284,7 @@ static jl_cgval_t emit_ifelse(jl_codectx_t &ctx, jl_cgval_t c, jl_cgval_t x, jl_
12691284 tindex = ret;
12701285 setName (ctx.emission_context , tindex, " ifelse_tindex" );
12711286 }
1272- jl_cgval_t ret = mark_julia_slot (ifelse_result, rt_hint, tindex, ifelse_tbaa);
1287+ jl_cgval_t ret = mark_julia_slot (ifelse_result, rt_hint, tindex, ifelse_tbaa, ifelse_roots );
12731288 if (x_vboxed || y_vboxed) {
12741289 if (!x_vboxed)
12751290 x_vboxed = ConstantPointerNull::get (cast<PointerType>(y_vboxed->getType ()));
0 commit comments