From 0fb83a8100f8a2445ce1b299273c6364cd58b350 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 29 Jul 2016 18:52:00 -0400 Subject: [PATCH] Optimize (if #f x y) to just y --- scheme/cyclone/cps-optimizations.sld | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/scheme/cyclone/cps-optimizations.sld b/scheme/cyclone/cps-optimizations.sld index c82ecde5..711bfe32 100644 --- a/scheme/cyclone/cps-optimizations.sld +++ b/scheme/cyclone/cps-optimizations.sld @@ -368,9 +368,14 @@ ((set!? exp) `(set! ,(opt:contract (set!->var exp)) ,(opt:contract (set!->exp exp)))) - ((if? exp) `(if ,(opt:contract (if->condition exp)) - ,(opt:contract (if->then exp)) - ,(opt:contract (if->else exp)))) + ((if? exp) + (cond + ((not (if->condition exp)) + (opt:contract (if->else exp))) + (else + `(if ,(opt:contract (if->condition exp)) + ,(opt:contract (if->then exp)) + ,(opt:contract (if->else exp)))))) ; Application: ((app? exp) (let* ((fnc (opt:contract (car exp)))) @@ -442,9 +447,14 @@ ((set!? exp) `(set! ,(set!->var exp) ,(opt:inline-prims (set!->exp exp) refs))) - ((if? exp) `(if ,(opt:inline-prims (if->condition exp) refs) - ,(opt:inline-prims (if->then exp) refs) - ,(opt:inline-prims (if->else exp) refs))) + ((if? exp) + (cond + ((not (if->condition exp)) + (opt:contract (if->else exp))) + (else + `(if ,(opt:inline-prims (if->condition exp) refs) + ,(opt:inline-prims (if->then exp) refs) + ,(opt:inline-prims (if->else exp) refs))))) ; Application: ((app? exp) ;(trace:error `(app? ,exp ,(ast:lambda? (car exp))