diff --git a/src/codegen.cpp b/src/codegen.cpp index 7759711c3f5ee3..8c33740979c5ab 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -6507,7 +6507,7 @@ static std::unique_ptr emit_function( }; // Codegen Phi nodes - std::map BB_rewrite_map; + std::map, BasicBlock*> BB_rewrite_map; std::vector ToDelete; for (auto &tup : ctx.PhiNodes) { jl_cgval_t phi_result; @@ -6526,8 +6526,9 @@ static std::unique_ptr emit_function( Value *V = NULL; BasicBlock *IncomingBB = come_from_bb[edge]; BasicBlock *FromBB = IncomingBB; - if (BB_rewrite_map.count(FromBB)) { - FromBB = BB_rewrite_map[IncomingBB]; + std::pair LookupKey(IncomingBB, PhiBB); + if (BB_rewrite_map.count(LookupKey)) { + FromBB = BB_rewrite_map[LookupKey]; } #ifndef JL_NDEBUG bool found_pred = false; @@ -6681,7 +6682,7 @@ static std::unique_ptr emit_function( // Check any phi nodes in the Phi block to see if by splitting the edges, // we made things inconsistent if (FromBB != ctx.builder.GetInsertBlock()) { - BB_rewrite_map[IncomingBB] = ctx.builder.GetInsertBlock(); + BB_rewrite_map[LookupKey] = ctx.builder.GetInsertBlock(); for (BasicBlock::iterator I = PhiBB->begin(); isa(I); ++I) { PHINode *PN = cast(I); ssize_t BBIdx = PN->getBasicBlockIndex(FromBB); diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 367a296cbc8923..5e75bc10bca1cd 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -1606,10 +1606,11 @@ ;; TODO avoid `local declared twice` error from this ;;,@(if outer `((local ,lhs)) '()) ,@(if outer `((require-existing-local ,lhs)) '()) - (_while - (call (|.| (core Intrinsics) 'not_int) (call (core ===) ,next (null))) - (block ,body - (= ,next (call (top iterate) ,coll ,state))))))))))) + (if (call (top not_int) (call (core ===) ,next (null))) + (_do_while + (block ,body + (= ,next (call (top iterate) ,coll ,state))) + (call (|.| (core Intrinsics) 'not_int) (call (core ===) ,next (null)))))))))))) ;; wrap `expr` in a function appropriate for consuming values from given ranges (define (func-for-generator-ranges expr range-exprs flat outervars) @@ -3644,6 +3645,14 @@ f(x) = yt(x) (compile (caddr e) break-labels #f #f) (emit `(goto ,topl)) (mark-label endl))) + ((_do_while) + (let* ((endl (make-label)) + (topl (make&mark-label))) + (compile (cadr e) break-labels #f #f) + (let ((test (compile-cond (caddr e) break-labels))) + (emit `(gotoifnot ,test ,endl))) + (emit `(goto ,topl)) + (mark-label endl))) ((break-block) (let ((endl (make-label))) (begin0 (compile (caddr e)