Skip to content

Commit

Permalink
compile simple loop conditions twice for a more efficient branch stru…
Browse files Browse the repository at this point in the history
…cture

I didn't think this would matter, but it actually makes a big difference
to LLVM. fixes #5469

with this, I believe no changes to Range1 are needed for performance.
  • Loading branch information
JeffBezanson committed Mar 13, 2014
1 parent 9e0e3bd commit 14d0a7d
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2914,13 +2914,28 @@ So far only the second case can actually occur.
(set-car! (cdr end-jump) (make&mark-label)))))
((block) (for-each (lambda (x) (compile x break-labels vi))
(cdr e)))
((_while) (let ((topl (make&mark-label))
(endl (make-label)))
(compile (cadr e) break-labels vi)
(emit `(gotoifnot ,(goto-form (caddr e)) ,endl))
(compile (cadddr e) break-labels vi)
(emit `(goto ,topl))
(mark-label endl)))
((_while)
(let ((test-blk (cadr e))
(endl (make-label)))
(if (or (atom? test-blk) (equal? test-blk '(block)))
;; if condition is simple, compile it twice in order
;; to generate a single branch per iteration.
(let ((topl (make-label)))
(compile test-blk break-labels vi)
(emit `(gotoifnot ,(goto-form (caddr e)) ,endl))
(mark-label topl)
(compile (cadddr e) break-labels vi)
(compile test-blk break-labels vi)
(emit `(gotoifnot (call (top !) ,(goto-form (caddr e))) ,topl))
(mark-label endl))

(let ((topl (make&mark-label)))
(compile test-blk break-labels vi)
(emit `(gotoifnot ,(goto-form (caddr e)) ,endl))
(compile (cadddr e) break-labels vi)
(emit `(goto ,topl))
(mark-label endl)))))

((break-block) (let ((endl (make-label)))
(compile (caddr e)
(cons (list (cadr e) endl handler-level)
Expand Down

1 comment on commit 14d0a7d

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

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

Awesome :-)

Nevertheless, I think we should change Range1 to avoid lousy interaction with type promotion. For example, character ranges and date ranges are much better if you can just repeatedly increment a value until it exceeds some other value.

Please sign in to comment.