You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by mb...@apache.org on 2017/08/09 20:52:59 UTC

[1/4] systemml git commit: [MINOR][SYSTEMML-1741] Improved graph traversal on codegen plan costing

Repository: systemml
Updated Branches:
  refs/heads/master c2124544d -> c170374e7


[MINOR][SYSTEMML-1741] Improved graph traversal on codegen plan costing 

This patch makes a minor improvement of the codegen graph traversal for
plan costing by stopping at partition boundaries instead of traversing
to the leafs without taking the costs into account. On lenet this led to
a minor but consistent improvement of codegen compilation overheads from
14.4s to 13.1s (for enumerating 474,840 plans).


Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/0221fbcd
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/0221fbcd
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/0221fbcd

Branch: refs/heads/master
Commit: 0221fbcd0d3c09c0aef37ee7e77863ecdc0446b4
Parents: c212454
Author: Matthias Boehm <mb...@gmail.com>
Authored: Mon Aug 7 13:17:32 2017 -0700
Committer: Matthias Boehm <mb...@gmail.com>
Committed: Wed Aug 9 13:52:49 2017 -0700

----------------------------------------------------------------------
 .../sysml/hops/codegen/opt/PlanSelection.java   |  3 +-
 .../opt/PlanSelectionFuseCostBasedV2.java       | 50 +++++++++-----------
 2 files changed, 24 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/0221fbcd/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelection.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelection.java b/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelection.java
index 23cc128..d18d156 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelection.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelection.java
@@ -98,8 +98,7 @@ public abstract class PlanSelection
 				return Integer.compare(o1.type.getRank(), o2.type.getRank());
 			
 			//for same type, prefer plan with more refs
-			return Integer.compare(
-				3-o1.countPlanRefs(), 3-o2.countPlanRefs());
+			return Integer.compare(-o1.countPlanRefs(), -o2.countPlanRefs());
 		}
 	}
 	

http://git-wip-us.apache.org/repos/asf/systemml/blob/0221fbcd/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java b/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java
index 2fa0de7..717a059 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/opt/PlanSelectionFuseCostBasedV2.java
@@ -744,11 +744,9 @@ public class PlanSelectionFuseCostBasedV2 extends PlanSelection
 		//memoization per hop id and cost vector to account for redundant
 		//computation without double counting materialized results or compute
 		//costs of complex operation DAGs within a single fused operator
-		VisitMarkCost tag = new VisitMarkCost(current.getHopID(), 
-			(costsCurrent==null || currentType==TemplateType.MAGG)?0:costsCurrent.ID);
-		if( visited.contains(tag) )
-			return 0;
-		visited.add(tag);
+		if( !visited.add(new VisitMarkCost(current.getHopID(), 
+			(costsCurrent==null || currentType==TemplateType.MAGG)?0:costsCurrent.ID)) )
+			return 0; //already existing 
 		
 		//open template if necessary, including memoization
 		//under awareness of current plan choice
@@ -792,8 +790,7 @@ public class PlanSelectionFuseCostBasedV2 extends PlanSelection
 		}
 		
 		//add compute costs of current operator to costs vector
-		if( part.getPartition().contains(current.getHopID()) )
-			costVect.computeCosts += computeCosts.get(current.getHopID());
+		costVect.computeCosts += computeCosts.get(current.getHopID());
 		
 		//process children recursively
 		for( int i=0; i< current.getInput().size(); i++ ) {
@@ -803,34 +800,33 @@ public class PlanSelectionFuseCostBasedV2 extends PlanSelection
 			else if( best!=null && isImplicitlyFused(current, i, best.type) )
 				costVect.addInputSize(c.getInput().get(0).getHopID(), getSize(c));
 			else { //include children and I/O costs
-				costs += rGetPlanCosts(memo, c, visited, part, matPoints, plan, computeCosts, null, null);
+				if( part.getPartition().contains(c.getHopID()) )
+					costs += rGetPlanCosts(memo, c, visited, part, matPoints, plan, computeCosts, null, null);
 				if( costVect != null && c.getDataType().isMatrix() )
 					costVect.addInputSize(c.getHopID(), getSize(c));
 			}
 		}
 		
 		//add costs for opened fused operator
-		if( part.getPartition().contains(current.getHopID()) ) {
-			if( opened ) {
-				if( LOG.isTraceEnabled() ) {
-					String type = (best !=null) ? best.type.name() : "HOP";
-					LOG.trace("Cost vector ("+type+" "+current.getHopID()+"): "+costVect);
-				}
-				double tmpCosts = costVect.outSize * 8 / WRITE_BANDWIDTH //time for output write
-					+ Math.max(costVect.getSumInputSizes() * 8 / READ_BANDWIDTH,
-					costVect.computeCosts*costVect.getMaxInputSize()/ COMPUTE_BANDWIDTH);
-				//sparsity correction for outer-product template (and sparse-safe cell)
-				if( best != null && best.type == TemplateType.OUTER ) {
-					Hop driver = memo.getHopRefs().get(costVect.getMaxInputSizeHopID());
-					tmpCosts *= driver.dimsKnown(true) ? driver.getSparsity() : SPARSE_SAFE_SPARSITY_EST;
-				}
-				costs += tmpCosts;
+		if( opened ) {
+			if( LOG.isTraceEnabled() ) {
+				String type = (best !=null) ? best.type.name() : "HOP";
+				LOG.trace("Cost vector ("+type+" "+current.getHopID()+"): "+costVect);
 			}
-			//add costs for non-partition read in the middle of fused operator
-			else if( part.getExtConsumed().contains(current.getHopID()) ) {
-				costs += rGetPlanCosts(memo, current, visited,
-					part, matPoints, plan, computeCosts, null, null);
+			double tmpCosts = costVect.outSize * 8 / WRITE_BANDWIDTH //time for output write
+				+ Math.max(costVect.getSumInputSizes() * 8 / READ_BANDWIDTH,
+				costVect.computeCosts*costVect.getMaxInputSize()/ COMPUTE_BANDWIDTH);
+			//sparsity correction for outer-product template (and sparse-safe cell)
+			if( best != null && best.type == TemplateType.OUTER ) {
+				Hop driver = memo.getHopRefs().get(costVect.getMaxInputSizeHopID());
+				tmpCosts *= driver.dimsKnown(true) ? driver.getSparsity() : SPARSE_SAFE_SPARSITY_EST;
 			}
+			costs += tmpCosts;
+		}
+		//add costs for non-partition read in the middle of fused operator
+		else if( part.getExtConsumed().contains(current.getHopID()) ) {
+			costs += rGetPlanCosts(memo, current, visited,
+				part, matPoints, plan, computeCosts, null, null);
 		}
 		
 		//sanity check non-negative costs


[2/4] systemml git commit: [SYSTEMML-1828, 1832] New rewrite for merging statement block sequences

Posted by mb...@apache.org.
http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/wdivmmbasic.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wdivmmbasic.dml b/src/test/scripts/functions/codegen/wdivmmbasic.dml
index dc74699..4c2365b 100644
--- a/src/test/scripts/functions/codegen/wdivmmbasic.dml
+++ b/src/test/scripts/functions/codegen/wdivmmbasic.dml
@@ -23,7 +23,7 @@ X = matrix( 3, rows=1000, cols=1500)
 U = matrix( 4, rows=1000, cols=10)
 V = matrix( 5, rows=1500, cols=10)
 
-if(1==1){}
+while(FALSE){}
 
 eps = 0.1
 S= X/((U%*%t(V))+eps);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/wsigmoid.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wsigmoid.dml b/src/test/scripts/functions/codegen/wsigmoid.dml
index 3841c3b..a0a247e 100644
--- a/src/test/scripts/functions/codegen/wsigmoid.dml
+++ b/src/test/scripts/functions/codegen/wsigmoid.dml
@@ -23,7 +23,7 @@ X = matrix( 3, rows=1000, cols=2000)
 U = matrix( 4, rows=1000, cols=10)
 V = matrix( 5, rows=2000, cols=10)
 
-if(1==1){}
+while(FALSE){}
 
 eps = 0.1
 S= X*(1/(1+exp(-(U%*%t(V)))));

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/frame/FrameFunction.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/frame/FrameFunction.dml b/src/test/scripts/functions/frame/FrameFunction.dml
index 591e63b..843ef7c 100644
--- a/src/test/scripts/functions/frame/FrameFunction.dml
+++ b/src/test/scripts/functions/frame/FrameFunction.dml
@@ -23,7 +23,7 @@ foo = function(Frame[String] F, String jspec)
   return (Matrix[Double] RX, Frame[String] RM) 
 {
   #prevent function inlining
-  if( 1==1 ){}
+  while(FALSE){}
 
   [RX, RM] = transformencode(target=F, spec=jspec);
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/frame/FrameMetaReadWrite.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/frame/FrameMetaReadWrite.dml b/src/test/scripts/functions/frame/FrameMetaReadWrite.dml
index 8c4130d..6c1dc5f 100644
--- a/src/test/scripts/functions/frame/FrameMetaReadWrite.dml
+++ b/src/test/scripts/functions/frame/FrameMetaReadWrite.dml
@@ -20,7 +20,7 @@
 #-------------------------------------------------------------
 
 A = read($1, data_type="frame", rows=$2, cols=$3, format=$4);
-if(1==1){}
+while(FALSE){}
 
 B = A;
 write(B, $5, format=$4);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/frame/FrameSchemaRead1.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/frame/FrameSchemaRead1.dml b/src/test/scripts/functions/frame/FrameSchemaRead1.dml
index be96621..e7b126f 100644
--- a/src/test/scripts/functions/frame/FrameSchemaRead1.dml
+++ b/src/test/scripts/functions/frame/FrameSchemaRead1.dml
@@ -21,7 +21,7 @@
 
 
 A = read($1, data_type="frame", schema=$2, rows=$3, cols=$4, format="csv");
-if(1==1){}
+while(FALSE){}
 
 B = A;
 write(B, $5, format="binary");

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/frame/FrameSchemaRead2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/frame/FrameSchemaRead2.dml b/src/test/scripts/functions/frame/FrameSchemaRead2.dml
index 88766c9..6b34c18 100644
--- a/src/test/scripts/functions/frame/FrameSchemaRead2.dml
+++ b/src/test/scripts/functions/frame/FrameSchemaRead2.dml
@@ -21,7 +21,7 @@
 
 
 A = read($1, data_type="frame", rows=$3, cols=$4, format="csv");
-if(1==1){}
+while(FALSE){}
 
 B = A;
 write(B, $5, format="binary");       

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/indexing/RowBatchIndexingTest.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/indexing/RowBatchIndexingTest.dml b/src/test/scripts/functions/indexing/RowBatchIndexingTest.dml
index 164de84..4fbfa58 100644
--- a/src/test/scripts/functions/indexing/RowBatchIndexingTest.dml
+++ b/src/test/scripts/functions/indexing/RowBatchIndexingTest.dml
@@ -24,7 +24,7 @@ A = read($1)
 s = 0;
 for( i in 1:nrow(A)/500 ) {
   Xi = A[((i-1)*500+1):(i*500),]
-  if(1==1){}
+  while(FALSE){}
   s = s + sum(Xi);
 }
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/IPAConstantFoldingScalarVariablePropagation1.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/IPAConstantFoldingScalarVariablePropagation1.dml b/src/test/scripts/functions/misc/IPAConstantFoldingScalarVariablePropagation1.dml
index 17f4bb3..2f7df82 100644
--- a/src/test/scripts/functions/misc/IPAConstantFoldingScalarVariablePropagation1.dml
+++ b/src/test/scripts/functions/misc/IPAConstantFoldingScalarVariablePropagation1.dml
@@ -50,7 +50,7 @@ dWc1_agg = matrix(0, rows=num_batches, cols=nrow(Wc1)*ncol(Wc1))
 # Imagine that a loop over mini-batches would go here, but for this test, we will
 # hardcode to the first iteration.
 j = 1
-if (1==1) {print("HI")}  # cut DAG!
+while(FALSE){}  # cut DAG!
 
 # Get a mini-batch in this group
 beg = ((j-1) * batch_size) + 1
@@ -83,5 +83,5 @@ doutc1_agg[j,] = matrix(doutc1, rows=1, cols=batch_size*F1*Hin*Win)
 dWc1_agg[j,] = matrix(dWc1, rows=1, cols=nrow(Wc1)*ncol(Wc1))
 
 # Print outputs to force execution
-if (1==1) {print("HI")}  # cut DAG!
+while(FALSE){} # cut DAG!
 print(sum(doutc1_agg) + " " + sum(dWc1_agg))

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/IPAConstantFoldingScalarVariablePropagation2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/IPAConstantFoldingScalarVariablePropagation2.dml b/src/test/scripts/functions/misc/IPAConstantFoldingScalarVariablePropagation2.dml
index 0e29a7a..ec1a7fc 100644
--- a/src/test/scripts/functions/misc/IPAConstantFoldingScalarVariablePropagation2.dml
+++ b/src/test/scripts/functions/misc/IPAConstantFoldingScalarVariablePropagation2.dml
@@ -51,7 +51,7 @@ dWc1_agg = matrix(0, rows=num_batches, cols=nrow(Wc1)*ncol(Wc1))
 # Imagine that a loop over mini-batches would go here, but for this test, we will
 # hardcode to the first iteration.
 j = 1
-if (1==1) {print("HI")}  # cut DAG!
+while(FALSE){}  # cut DAG!
 
 # Get a mini-batch in this group
 beg = ((j-1) * batch_size) + 1
@@ -86,5 +86,5 @@ doutc1_agg[j,] = matrix(doutc1, rows=1, cols=batch_size*F1*Hin*Win)
 dWc1_agg[j,] = matrix(dWc1, rows=1, cols=nrow(Wc1)*ncol(Wc1))
 
 # Print outputs to force execution
-if (1==1) {print("HI")}  # cut DAG!
+while(FALSE){}  # cut DAG!
 print(sum(doutc1_agg) + " " + sum(dWc1_agg))

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/IPANnzPropagation1.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/IPANnzPropagation1.dml b/src/test/scripts/functions/misc/IPANnzPropagation1.dml
index 919dc32..711302a 100644
--- a/src/test/scripts/functions/misc/IPANnzPropagation1.dml
+++ b/src/test/scripts/functions/misc/IPANnzPropagation1.dml
@@ -20,7 +20,7 @@
 #-------------------------------------------------------------
 
 foo = function(matrix[double] X) return (double sum) {
-    if( 1==1 ) {}
+    while(FALSE){}
     sum = sum(X);
 }
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/IPANnzPropagation2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/IPANnzPropagation2.dml b/src/test/scripts/functions/misc/IPANnzPropagation2.dml
index 86990ca..de0a1df 100644
--- a/src/test/scripts/functions/misc/IPANnzPropagation2.dml
+++ b/src/test/scripts/functions/misc/IPANnzPropagation2.dml
@@ -20,7 +20,7 @@
 #-------------------------------------------------------------
 
 foo = function(matrix[double] X) return (double sum) {
-    if( 1==1 ) {}
+    while(FALSE){}
     sum = sum(X);
 }
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/ReadAfterWriteMatrix2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/ReadAfterWriteMatrix2.dml b/src/test/scripts/functions/misc/ReadAfterWriteMatrix2.dml
index bfbb81d..2ffa496 100644
--- a/src/test/scripts/functions/misc/ReadAfterWriteMatrix2.dml
+++ b/src/test/scripts/functions/misc/ReadAfterWriteMatrix2.dml
@@ -23,7 +23,7 @@
 A = rand(rows=10, cols=10);
 write(A, $1);
 
-if(1==1){}
+while(FALSE){}
 
 B = read($2);
 print(sum(B));

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/ReadAfterWriteScalar2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/ReadAfterWriteScalar2.dml b/src/test/scripts/functions/misc/ReadAfterWriteScalar2.dml
index 43ff306..05a4158 100644
--- a/src/test/scripts/functions/misc/ReadAfterWriteScalar2.dml
+++ b/src/test/scripts/functions/misc/ReadAfterWriteScalar2.dml
@@ -23,7 +23,7 @@
 A = 7;
 write(A, $1);
 
-if(1==1){}
+while(FALSE){}
 
 B = read($2);
 print(B);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewriteCSETransposeScalarMult.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewriteCSETransposeScalarMult.dml b/src/test/scripts/functions/misc/RewriteCSETransposeScalarMult.dml
index 07e67dc..0a7dcf6 100644
--- a/src/test/scripts/functions/misc/RewriteCSETransposeScalarMult.dml
+++ b/src/test/scripts/functions/misc/RewriteCSETransposeScalarMult.dml
@@ -20,12 +20,12 @@
 #-------------------------------------------------------------
 
 X = rand(rows=$1, cols=$2, min=1, max=10);
-if(1==1){}
+while(FALSE){}
 
 a = t(X);
 b = t(2*X);
 
-if(1==1){}
+while(FALSE){}
 
 R = sum(2*a == b);
 write(R, $3);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewriteCSETransposeScalarPow.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewriteCSETransposeScalarPow.dml b/src/test/scripts/functions/misc/RewriteCSETransposeScalarPow.dml
index f47c227..bf8f7ea 100644
--- a/src/test/scripts/functions/misc/RewriteCSETransposeScalarPow.dml
+++ b/src/test/scripts/functions/misc/RewriteCSETransposeScalarPow.dml
@@ -20,12 +20,12 @@
 #-------------------------------------------------------------
 
 X = rand(rows=$1, cols=$2, min=1, max=10);
-if(1==1){}
+while(FALSE){}
 
 a = t(X);
 b = t(X^2);
 
-if(1==1){}
+while(FALSE){}
 
 R = sum(a^2 == b);
 write(R, $3);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest1.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest1.dml b/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest1.dml
index 077b8a9..dbac1a1 100644
--- a/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest1.dml
+++ b/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest1.dml
@@ -21,7 +21,7 @@
 
 X=matrix(1,rows=10,cols=10)
 Y=matrix(1,rows=10,cols=10)
-if(1==1){}
+while(FALSE){}
 lamda=7
 S=X+lamda*Y
 write(S,$1)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest2.dml b/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest2.dml
index f3c6b9a..bae013a 100644
--- a/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest2.dml
+++ b/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest2.dml
@@ -21,7 +21,7 @@
 
 X=matrix(1,rows=10,cols=10)
 Y=matrix(1,rows=10,cols=10)
-if(1==1){}
+while(FALSE){}
 lamda=7
 S=X-lamda*Y
 write(S,$1)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest3.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest3.dml b/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest3.dml
index af84884..a80669c 100644
--- a/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest3.dml
+++ b/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest3.dml
@@ -21,7 +21,7 @@
 
 X=matrix(1,rows=10,cols=10)
 Y=matrix(1,rows=10,cols=10)
-if(1==1){}
+while(FALSE){}
 lamda=7
 S=lamda*Y+X
 write(S,$1)
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest4.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest4.dml b/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest4.dml
index 0599f02..85c023d 100644
--- a/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest4.dml
+++ b/src/test/scripts/functions/misc/RewriteFuseBinaryOpChainTest4.dml
@@ -22,7 +22,7 @@
 X = matrix(1, 10, 1);
 Y = matrix(2, 1, 10);
 lambda = 7;
-if(1==1){}
+while(FALSE){}
 
 S = outer(X, lambda*Y, "+");
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewriteFusedRand.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewriteFusedRand.dml b/src/test/scripts/functions/misc/RewriteFusedRand.dml
index 6e2cb58..ab00f04 100644
--- a/src/test/scripts/functions/misc/RewriteFusedRand.dml
+++ b/src/test/scripts/functions/misc/RewriteFusedRand.dml
@@ -21,7 +21,7 @@
 
 X1 = rand(rows=$1, cols=$2, pdf=$3, seed=$4) * 7;
 
-if(1==1){} #prevent cse
+while(FALSE){} #prevent cse
 
 X2 = rand(rows=$1, cols=$2, pdf=$3, seed=$4) * 7;
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewriteMergeFunctionCut.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewriteMergeFunctionCut.R b/src/test/scripts/functions/misc/RewriteMergeFunctionCut.R
new file mode 100644
index 0000000..5c3d7ce
--- /dev/null
+++ b/src/test/scripts/functions/misc/RewriteMergeFunctionCut.R
@@ -0,0 +1,36 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+
+args <- commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+library("matrixStats")
+
+X = matrix(0.5, 600, 10);
+ssX_V = matrix(0.9, 10, 1);
+P = matrix(0.7, 600, 2);
+
+Q = P[,1:1] * (X %*% ssX_V);
+Y = X;
+R = t(X) %*% (Q - P[,1:1] * rowSums(Q));
+
+writeMM(as(R, "CsparseMatrix"), paste(args[1], "R", sep="")); 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewriteMergeFunctionCut.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewriteMergeFunctionCut.dml b/src/test/scripts/functions/misc/RewriteMergeFunctionCut.dml
new file mode 100644
index 0000000..9e247a9
--- /dev/null
+++ b/src/test/scripts/functions/misc/RewriteMergeFunctionCut.dml
@@ -0,0 +1,38 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+printAndAssign = function(Matrix[Double] X) return (Matrix[Double] Y) {
+	if( sum(X) > 0 )
+     print("sum(X) = " + sum(X));
+  Y = X;
+}
+
+
+X = matrix(0.5, 600, 10);
+ssX_V = matrix(0.9, 10, 1);
+P = matrix(0.7, 600, 2);
+
+Q = P[,1:1] * (X %*% ssX_V);
+Y = X + 2;
+Y = printAndAssign(X);
+R = t(X) %*% (Q - P[,1:1] * rowSums(Q));
+
+write(R, $1);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewriteMergeIfCut.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewriteMergeIfCut.R b/src/test/scripts/functions/misc/RewriteMergeIfCut.R
new file mode 100644
index 0000000..a034ef1
--- /dev/null
+++ b/src/test/scripts/functions/misc/RewriteMergeIfCut.R
@@ -0,0 +1,35 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+
+args <- commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+library("matrixStats")
+
+X = matrix(0.5, 600, 10);
+ssX_V = matrix(0.9, 10, 1);
+P = matrix(0.7, 600, 2);
+
+Q = P[,1:1] * (X %*% ssX_V);
+R = t(X) %*% (Q - P[,1:1] * rowSums(Q));
+
+writeMM(as(R, "CsparseMatrix"), paste(args[1], "R", sep="")); 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewriteMergeIfCut.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewriteMergeIfCut.dml b/src/test/scripts/functions/misc/RewriteMergeIfCut.dml
new file mode 100644
index 0000000..cde0edf
--- /dev/null
+++ b/src/test/scripts/functions/misc/RewriteMergeIfCut.dml
@@ -0,0 +1,31 @@
+#-------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#-------------------------------------------------------------
+
+
+X = matrix(0.5, 600, 10);
+ssX_V = matrix(0.9, 10, 1);
+P = matrix(0.7, 600, 2);
+
+Q = P[,1:1] * (X %*% ssX_V);
+if(1==1){}
+R = t(X) %*% (Q - P[,1:1] * rowSums(Q));
+
+write(R, $1);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewritePushdownSumBinaryMult.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewritePushdownSumBinaryMult.dml b/src/test/scripts/functions/misc/RewritePushdownSumBinaryMult.dml
index 9850242..9b7f6ce 100644
--- a/src/test/scripts/functions/misc/RewritePushdownSumBinaryMult.dml
+++ b/src/test/scripts/functions/misc/RewritePushdownSumBinaryMult.dml
@@ -20,7 +20,7 @@
 #-------------------------------------------------------------
 
 X=matrix(1,10,10)
-if(1==1){}
+while(FALSE){}
 lamda=sum(X)
 y=sum(lamda*X)
 write(y, $1)

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/RewritePushdownSumBinaryMult2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/RewritePushdownSumBinaryMult2.dml b/src/test/scripts/functions/misc/RewritePushdownSumBinaryMult2.dml
index 07e0e54..c200dd0 100644
--- a/src/test/scripts/functions/misc/RewritePushdownSumBinaryMult2.dml
+++ b/src/test/scripts/functions/misc/RewritePushdownSumBinaryMult2.dml
@@ -20,7 +20,7 @@
 #-------------------------------------------------------------
 
 X=matrix(1,10,10)
-if(1==1){}
+while(FALSE){}
 lamda=sum(X)
 y=sum(X*lamda)
 write(y, $1)

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/dt_change_4c.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/dt_change_4c.dml b/src/test/scripts/functions/misc/dt_change_4c.dml
index 3cf60fa..988fab3 100644
--- a/src/test/scripts/functions/misc/dt_change_4c.dml
+++ b/src/test/scripts/functions/misc/dt_change_4c.dml
@@ -22,7 +22,7 @@
 
 foo = function(Matrix[Double] input) return (Double out) 
 {
-   if( 1==1 ){} #prevent inlining
+   while(FALSE){} #prevent inlining
   
    out = as.scalar(input[1,1]);
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/dt_change_4d.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/dt_change_4d.dml b/src/test/scripts/functions/misc/dt_change_4d.dml
index e04683d..13d8519 100644
--- a/src/test/scripts/functions/misc/dt_change_4d.dml
+++ b/src/test/scripts/functions/misc/dt_change_4d.dml
@@ -22,7 +22,7 @@
 
 foo = function(Integer input) return (Matrix[Double] out) 
 {
-   if( 1==1 ){} #prevent inlining
+   while(FALSE){} #prevent inlining
    out = matrix(1, rows=10, cols=10);
    out = out*input;
    #out = matrix(input, rows=10, cols=10); unsupported expression in rand

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/dt_change_4e.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/dt_change_4e.dml b/src/test/scripts/functions/misc/dt_change_4e.dml
index 413bc12..f6947d8 100644
--- a/src/test/scripts/functions/misc/dt_change_4e.dml
+++ b/src/test/scripts/functions/misc/dt_change_4e.dml
@@ -22,7 +22,7 @@
 
 Y = matrix(1, rows=10, cols=10);
 X = matrix(7, rows=10, cols=10);
-if(1==1){}
+while(FALSE){}
 X = 7;
 
 print("Result: "+sum(X + Y));

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/dt_change_4f.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/dt_change_4f.dml b/src/test/scripts/functions/misc/dt_change_4f.dml
index 1050a2c..0fb23aa 100644
--- a/src/test/scripts/functions/misc/dt_change_4f.dml
+++ b/src/test/scripts/functions/misc/dt_change_4f.dml
@@ -22,7 +22,7 @@
 
 Y = matrix(1, rows=10, cols=10);
 X = matrix(7, rows=10, cols=10);
-if(1==1){}
+while(FALSE){}
 X = as.scalar(X[1,1]);
 
 print("Result: "+sum(X + Y));

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/misc/functionNoInlining.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/misc/functionNoInlining.dml b/src/test/scripts/functions/misc/functionNoInlining.dml
index cdcc67b..14e83b8 100644
--- a/src/test/scripts/functions/misc/functionNoInlining.dml
+++ b/src/test/scripts/functions/misc/functionNoInlining.dml
@@ -22,16 +22,14 @@
 
 foo = function(Double input) return (Double out)
 {
-   if( 1==1 ){ #prevent inlining
-      out = input + input;
-   }
+   while(FALSE){} #prevent inlining
+   out = input + input;
 }
 
 foo2 = function(Integer input) return (Double out)
 { 
-   if( 1==1 ){ #prevent inlining
-      out = input + input;
-   }
+   while(FALSE){} #prevent inlining
+   out = input + input;
 }
 
 x = $1;

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/parfor/parfor49b.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/parfor/parfor49b.dml b/src/test/scripts/functions/parfor/parfor49b.dml
index 4035d9a..f67daec 100644
--- a/src/test/scripts/functions/parfor/parfor49b.dml
+++ b/src/test/scripts/functions/parfor/parfor49b.dml
@@ -22,7 +22,7 @@
 
 foo = function (Integer inval) return (Matrix[Double] out)
 {   
-   if( 1==1 ) {} #prevent inlining
+   while(FALSE){} #prevent inlining
    
    A = matrix( 1, rows=10, cols=10 );
    out = A

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/parfor/parfor_cdatapartition_leftindexing.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/parfor/parfor_cdatapartition_leftindexing.dml b/src/test/scripts/functions/parfor/parfor_cdatapartition_leftindexing.dml
index 2c6e1c9..c3bba05 100644
--- a/src/test/scripts/functions/parfor/parfor_cdatapartition_leftindexing.dml
+++ b/src/test/scripts/functions/parfor/parfor_cdatapartition_leftindexing.dml
@@ -29,7 +29,7 @@ R = matrix(0,rows=m,cols=n);
 parfor( i in 1:n, par=4, mode=LOCAL, datapartitioner=REMOTE_MR, opt=NONE )
 {
    col = V[,i];
-   if(1==1){}
+   while(FALSE){}
    R[,i] = col; 
 }   
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/parfor/parfor_rdatapartition_leftindexing.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/parfor/parfor_rdatapartition_leftindexing.dml b/src/test/scripts/functions/parfor/parfor_rdatapartition_leftindexing.dml
index b3fed2d..f771372 100644
--- a/src/test/scripts/functions/parfor/parfor_rdatapartition_leftindexing.dml
+++ b/src/test/scripts/functions/parfor/parfor_rdatapartition_leftindexing.dml
@@ -30,7 +30,7 @@ R = matrix(0,rows=m,cols=n);
 parfor( i in 1:m )
 {
    col = V[i,];
-   if(1==1){}
+   while(FALSE){}
    R[i,] = col; 
 }   
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/quaternary/WeightedDivMM4MultMinusLeft.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/quaternary/WeightedDivMM4MultMinusLeft.dml b/src/test/scripts/functions/quaternary/WeightedDivMM4MultMinusLeft.dml
index 87c035f..462e000 100644
--- a/src/test/scripts/functions/quaternary/WeightedDivMM4MultMinusLeft.dml
+++ b/src/test/scripts/functions/quaternary/WeightedDivMM4MultMinusLeft.dml
@@ -26,7 +26,7 @@ U = read($2);
 V = read($3);
 
 X = W/0.7;
-if(1==1){}
+while(FALSE){}
 R = t(t(U) %*% (W*(U%*%t(V)-X)));
 
 write(R, $4);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/quaternary/WeightedDivMM4MultMinusRight.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/quaternary/WeightedDivMM4MultMinusRight.dml b/src/test/scripts/functions/quaternary/WeightedDivMM4MultMinusRight.dml
index 7376abd..0f7652c 100644
--- a/src/test/scripts/functions/quaternary/WeightedDivMM4MultMinusRight.dml
+++ b/src/test/scripts/functions/quaternary/WeightedDivMM4MultMinusRight.dml
@@ -26,7 +26,7 @@ U = read($2);
 V = read($3);
 
 X = W/0.3
-if(1==1){}
+while(FALSE){}
 R = (W*(U%*%t(V)-X)) %*% V;
 
 write(R, $4);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/recompile/append_nnz.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/recompile/append_nnz.dml b/src/test/scripts/functions/recompile/append_nnz.dml
index 04cdf5d..4c10fcb 100644
--- a/src/test/scripts/functions/recompile/append_nnz.dml
+++ b/src/test/scripts/functions/recompile/append_nnz.dml
@@ -32,12 +32,13 @@ zero_cell = matrix (0, rows = 1, cols = 1);
 
 shift_X_cols = matrix (0, rows = 1, cols = m);
 
+while(FALSE){}
 if (intercept_status == 2) {
     X = (X + ones_n %*% shift_X_cols);
 }
 
 X = cbind (X, ones_n);
 
-if(1==1){ }
+while(FALSE){}
 
 print("sum="+sum(X)) 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/recompile/constant_propagation_if.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/recompile/constant_propagation_if.R b/src/test/scripts/functions/recompile/constant_propagation_if.R
index 1b86630..deb92e5 100644
--- a/src/test/scripts/functions/recompile/constant_propagation_if.R
+++ b/src/test/scripts/functions/recompile/constant_propagation_if.R
@@ -27,12 +27,8 @@ library("Matrix")
 
 numrows = as.integer(args[1]);
 numcols = as.integer(args[2]);
-
-if( 1==1 )
-{
-   numrows = numrows + 1;
-   numcols = numcols + 2;
-}  
+numrows = numrows + 1;
+numcols = numcols + 2;
 
 X = matrix(1, numrows, numcols);
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/recompile/constant_propagation_sb.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/recompile/constant_propagation_sb.R b/src/test/scripts/functions/recompile/constant_propagation_sb.R
index cfa6a00..f9c033f 100644
--- a/src/test/scripts/functions/recompile/constant_propagation_sb.R
+++ b/src/test/scripts/functions/recompile/constant_propagation_sb.R
@@ -28,18 +28,9 @@ library("Matrix")
 numrows = as.integer(args[1]);
 numcols = as.integer(args[2]);
 
-if( 1==1 ){}
-
 numrows2 = numrows;
 numcols2 = numcols;
 
-if( 1!=1 )
-{
-   numrows2 = numrows + 1;
-   numcols2 = numcols + 2;
-}  
-
-
 X = matrix(1, numrows2, numcols2);
 
 writeMM(as(X, "CsparseMatrix"), paste(args[3], "X", sep="")); 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/recompile/if_recompile_sparse.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/recompile/if_recompile_sparse.dml b/src/test/scripts/functions/recompile/if_recompile_sparse.dml
index 9b878cc..25bbd1a 100644
--- a/src/test/scripts/functions/recompile/if_recompile_sparse.dml
+++ b/src/test/scripts/functions/recompile/if_recompile_sparse.dml
@@ -21,15 +21,18 @@
 
 
 V = read($1);
-print(sum(V)); 
+print(sum(V));
+while(FALSE){}
 if( 1==1 ){
    V[1,1] = $2;
 }
 else {
    print(sum(V));
 }
+while(FALSE){}
 if( 1==1 ){
    print(sum(V));
 }
+while(FALSE){}
 
 write(V, $3);         
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/recompile/multiple_reads.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/recompile/multiple_reads.R b/src/test/scripts/functions/recompile/multiple_reads.R
index 9f86072..fa801c1 100644
--- a/src/test/scripts/functions/recompile/multiple_reads.R
+++ b/src/test/scripts/functions/recompile/multiple_reads.R
@@ -25,11 +25,6 @@ options(digits=22)
 
 library("Matrix")
 
-X <- readMM(paste(args[1], "X1.mtx", sep=""))
+X <- readMM(paste(args[1], "X2.mtx", sep=""))
 
-if( 1==1 )
-{
-   X <- readMM(paste(args[1], "X2.mtx", sep=""))
-}
-
-writeMM(as(X, "CsparseMatrix"), paste(args[2], "X", sep="")); 
\ No newline at end of file
+writeMM(as(X, "CsparseMatrix"), paste(args[2], "X", sep=""));

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/recompile/remove_empty_potpourri2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/recompile/remove_empty_potpourri2.dml b/src/test/scripts/functions/recompile/remove_empty_potpourri2.dml
index 70027dd..75eb2a0 100644
--- a/src/test/scripts/functions/recompile/remove_empty_potpourri2.dml
+++ b/src/test/scripts/functions/recompile/remove_empty_potpourri2.dml
@@ -24,6 +24,6 @@ A = matrix(0, rows=100,cols=1);
 R = colSums(A)
 
 #force original error on cpvar
-if(1==1){} 
+while(FALSE){} 
 
 write(R, $1);       
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/recompile/remove_empty_potpourri3.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/recompile/remove_empty_potpourri3.dml b/src/test/scripts/functions/recompile/remove_empty_potpourri3.dml
index a29acd6..7444f9c 100644
--- a/src/test/scripts/functions/recompile/remove_empty_potpourri3.dml
+++ b/src/test/scripts/functions/recompile/remove_empty_potpourri3.dml
@@ -21,7 +21,7 @@
 
 
 S = matrix(1,rows=100,cols=1);
-if(1==1){}
+while(FALSE){}
 
 A = diag(S);
 A = removeEmpty (target = A, margin = "rows");
@@ -30,7 +30,7 @@ C = table (B, seq (1, nrow(A), 1));
 R = removeEmpty (target = C, margin = "rows");
 R = R %*% A;
 
-if(1==1){} 
+while(FALSE){} 
 
 print(sum(R));
 write(R, $1);       
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/recompile/remove_empty_potpourri4.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/recompile/remove_empty_potpourri4.dml b/src/test/scripts/functions/recompile/remove_empty_potpourri4.dml
index 5158a38..1b15fef 100644
--- a/src/test/scripts/functions/recompile/remove_empty_potpourri4.dml
+++ b/src/test/scripts/functions/recompile/remove_empty_potpourri4.dml
@@ -25,7 +25,7 @@ B = matrix(1, rows=1000, cols=2);
 C = matrix(7, rows=1000, cols=1);
 D = matrix(3, rows=1000, cols=1);
 
-if(1==1){}
+while(FALSE){}
 
 tmp = cbind(X [, 1 : 2], B) * (C * (1 - D));
 E = removeEmpty (target = tmp, margin = "rows");
@@ -33,7 +33,7 @@ E = removeEmpty (target = tmp, margin = "rows");
 X = removeEmpty (target = X * C, margin = "rows");
 n = nrow (X);
 
-if(1==1){} 
+while(FALSE){} 
 
 R = X + sum(E) + n;
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/recompile/rewrite_mapmultchain1.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/recompile/rewrite_mapmultchain1.dml b/src/test/scripts/functions/recompile/rewrite_mapmultchain1.dml
index ab4eef2..0d93799 100644
--- a/src/test/scripts/functions/recompile/rewrite_mapmultchain1.dml
+++ b/src/test/scripts/functions/recompile/rewrite_mapmultchain1.dml
@@ -25,11 +25,11 @@ P = read($2);
 v = read($3);
 k = ncol(P);
 
-if(1==1){}
+while(FALSE){}
 
 Q = P * (X %*% v);
 HV = t(X) %*% (Q - P * (rowSums (Q) %*% matrix(1, rows=1, cols=k)));
 
-if(1==1){}
+while(FALSE){}
 
 write(HV, $4);       

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/recompile/rewrite_mapmultchain2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/recompile/rewrite_mapmultchain2.dml b/src/test/scripts/functions/recompile/rewrite_mapmultchain2.dml
index fa4db5f..bd62140 100644
--- a/src/test/scripts/functions/recompile/rewrite_mapmultchain2.dml
+++ b/src/test/scripts/functions/recompile/rewrite_mapmultchain2.dml
@@ -25,11 +25,11 @@ P = read($2);
 v = read($3);
 k = ncol(P);
 
-if(1==1){}
+while(FALSE){}
 
 Q = P[, 1:k] * (X %*% v);
 HV = t(X) %*% (Q - P[, 1:k] * (rowSums (Q) %*% matrix(1, rows=1, cols=k)));
         
-if(1==1){}
+while(FALSE){}
 
 write(HV, $4);       

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/reorg/Order.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/reorg/Order.dml b/src/test/scripts/functions/reorg/Order.dml
index 3ac2fce..a3fb3bd 100644
--- a/src/test/scripts/functions/reorg/Order.dml
+++ b/src/test/scripts/functions/reorg/Order.dml
@@ -22,7 +22,7 @@
 
 A = read($1);
 
-if(1==1){} #for recompilation rewrites
+while(FALSE){} #for recompilation rewrites
 
 B = order(target=A, by=$2, decreasing=$3, index.return=$4);
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/reorg/OrderDyn.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/reorg/OrderDyn.dml b/src/test/scripts/functions/reorg/OrderDyn.dml
index 35f4d0a..63b0a96 100644
--- a/src/test/scripts/functions/reorg/OrderDyn.dml
+++ b/src/test/scripts/functions/reorg/OrderDyn.dml
@@ -22,7 +22,7 @@
 
 A = read($1);
 
-if(1==1){} #for recompilation rewrites
+while(FALSE){} #for recompilation rewrites
 
 desc = (sum(A)>100)
 ixret = (sum(A)>200)

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/ternary/AAATernaryAggregateC.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/ternary/AAATernaryAggregateC.dml b/src/test/scripts/functions/ternary/AAATernaryAggregateC.dml
index b576a4d..cd2695a 100644
--- a/src/test/scripts/functions/ternary/AAATernaryAggregateC.dml
+++ b/src/test/scripts/functions/ternary/AAATernaryAggregateC.dml
@@ -21,7 +21,7 @@
 
 A = read($1);
 
-if(1==1){}
+while(FALSE){}
 
 R = colSums(A * A * A);
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/ternary/AAATernaryAggregateRC.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/ternary/AAATernaryAggregateRC.dml b/src/test/scripts/functions/ternary/AAATernaryAggregateRC.dml
index 7283703..527cbb1 100644
--- a/src/test/scripts/functions/ternary/AAATernaryAggregateRC.dml
+++ b/src/test/scripts/functions/ternary/AAATernaryAggregateRC.dml
@@ -21,7 +21,7 @@
 
 A = read($1);
 
-if(1==1){}
+while(FALSE){}
 
 s = sum(A * A * A);
 R = as.matrix(s);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/ternary/ABATernaryAggregateC.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/ternary/ABATernaryAggregateC.dml b/src/test/scripts/functions/ternary/ABATernaryAggregateC.dml
index 737b409..f0f87f4 100644
--- a/src/test/scripts/functions/ternary/ABATernaryAggregateC.dml
+++ b/src/test/scripts/functions/ternary/ABATernaryAggregateC.dml
@@ -22,7 +22,7 @@
 A = read($1);
 B = A * 2;
 
-if(1==1){}
+while(FALSE){}
 
 R = colSums(A * B * A);
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/ternary/ABATernaryAggregateRC.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/ternary/ABATernaryAggregateRC.dml b/src/test/scripts/functions/ternary/ABATernaryAggregateRC.dml
index 965c8d3..fd6c89c 100644
--- a/src/test/scripts/functions/ternary/ABATernaryAggregateRC.dml
+++ b/src/test/scripts/functions/ternary/ABATernaryAggregateRC.dml
@@ -22,7 +22,7 @@
 A = read($1);
 B = A * 2;
 
-if(1==1){}
+while(FALSE){}
 
 s = sum(A * B * A);
 R = as.matrix(s);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/ternary/CTableSequenceLeft.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/ternary/CTableSequenceLeft.dml b/src/test/scripts/functions/ternary/CTableSequenceLeft.dml
index 64facbf..755f2f6 100644
--- a/src/test/scripts/functions/ternary/CTableSequenceLeft.dml
+++ b/src/test/scripts/functions/ternary/CTableSequenceLeft.dml
@@ -25,5 +25,6 @@ B = table(seq(1, nrow(A)), A);
 if( $4==1 ){ #withAgg
    print("sum="+sum(B));
 }
+while(FALSE){}
 
 write(B, $5, format="text");
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/ternary/CTableSequenceRight.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/ternary/CTableSequenceRight.dml b/src/test/scripts/functions/ternary/CTableSequenceRight.dml
index ff4afed..4e449c6 100644
--- a/src/test/scripts/functions/ternary/CTableSequenceRight.dml
+++ b/src/test/scripts/functions/ternary/CTableSequenceRight.dml
@@ -25,5 +25,6 @@ B = table(A,seq(1, nrow(A)));
 if( $4==1 ){ #withAgg
    print("sum="+sum(B));
 }
+while(FALSE){}
 
 write(B, $5, format="text");
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/ternary/TernaryAggregateC.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/ternary/TernaryAggregateC.dml b/src/test/scripts/functions/ternary/TernaryAggregateC.dml
index a171ff4..822d24d 100644
--- a/src/test/scripts/functions/ternary/TernaryAggregateC.dml
+++ b/src/test/scripts/functions/ternary/TernaryAggregateC.dml
@@ -23,7 +23,7 @@ A = read($1);
 B = A * 2;
 C = A * 3;
 
-if(1==1){}
+while(FALSE){}
 
 R = colSums(A * B * C);
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/ternary/TernaryAggregateRC.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/ternary/TernaryAggregateRC.dml b/src/test/scripts/functions/ternary/TernaryAggregateRC.dml
index 485570d..b0f9fae 100644
--- a/src/test/scripts/functions/ternary/TernaryAggregateRC.dml
+++ b/src/test/scripts/functions/ternary/TernaryAggregateRC.dml
@@ -23,7 +23,7 @@ A = read($1);
 B = A * 2;
 C = A * 3;
 
-if(1==1){}
+while(FALSE){}
 
 s = sum(A * B * C);
 R = as.matrix(s);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/transform/FrameCSVReadWrite.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/transform/FrameCSVReadWrite.dml b/src/test/scripts/functions/transform/FrameCSVReadWrite.dml
index 88f0cf5..c376975 100644
--- a/src/test/scripts/functions/transform/FrameCSVReadWrite.dml
+++ b/src/test/scripts/functions/transform/FrameCSVReadWrite.dml
@@ -20,7 +20,7 @@
 #-------------------------------------------------------------
 
 X = read($1, data_type="frame", format="csv");
-if(1==1){}
+while(FALSE){}
 
 print(toString(X));
 write(X, $2, format="csv");

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/transform/TransformCSVFrameEncodeDecode.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/transform/TransformCSVFrameEncodeDecode.dml b/src/test/scripts/functions/transform/TransformCSVFrameEncodeDecode.dml
index 50ec83c..a38f105 100644
--- a/src/test/scripts/functions/transform/TransformCSVFrameEncodeDecode.dml
+++ b/src/test/scripts/functions/transform/TransformCSVFrameEncodeDecode.dml
@@ -24,7 +24,7 @@ jspec = "{\"ids\": true, \"recode\": [1,2,3]}";
 
 [X, M] = transformencode(target=F1, spec=jspec);
 
-if(1==1){}
+while(FALSE){}
 
 F2 = transformdecode(target=X, spec=jspec, meta=M);
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/transform/TransformFrameEncodeApply.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/transform/TransformFrameEncodeApply.dml b/src/test/scripts/functions/transform/TransformFrameEncodeApply.dml
index 08c98d0..f7be1aa 100644
--- a/src/test/scripts/functions/transform/TransformFrameEncodeApply.dml
+++ b/src/test/scripts/functions/transform/TransformFrameEncodeApply.dml
@@ -25,7 +25,7 @@ jspec = read($TFSPEC, data_type="scalar", value_type="string");
 
 [X, M] = transformencode(target=F1, spec=jspec);
 
-if(1==1){}
+while(FALSE){}
 
 X2 = transformapply(target=F1, spec=jspec, meta=M);
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/transform/TransformFrameEncodeDecode.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/transform/TransformFrameEncodeDecode.dml b/src/test/scripts/functions/transform/TransformFrameEncodeDecode.dml
index 0b2b6b7..ac9a5d2 100644
--- a/src/test/scripts/functions/transform/TransformFrameEncodeDecode.dml
+++ b/src/test/scripts/functions/transform/TransformFrameEncodeDecode.dml
@@ -23,7 +23,7 @@ jspec = read($TFSPEC, data_type="scalar", value_type="string");
 
 [X, M] = transformencode(target=F1, spec=jspec);
 
-if(1==1){}
+while(FALSE){}
 
 F2 = transformdecode(target=X, spec=jspec, meta=M);
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/unary/matrix/PrintTest.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/unary/matrix/PrintTest.dml b/src/test/scripts/functions/unary/matrix/PrintTest.dml
index 50cdc1c..dfabc2a 100644
--- a/src/test/scripts/functions/unary/matrix/PrintTest.dml
+++ b/src/test/scripts/functions/unary/matrix/PrintTest.dml
@@ -21,13 +21,13 @@
 
 X = read($1, rows=$2, cols=$3);
 X = X*1;
-if(1==1){} #ensure X is in symbol table
+while(FALSE){} #ensure X is in symbol table
 print("X");
-if(1==1){} #ensure X is in symbol table
+while(FALSE){} #ensure X is in symbol table
 y = (ncol(X));
-if(1==1){} #ensure y is in symbol table
+while(FALSE){} #ensure y is in symbol table
 print("y");
-if(1==1){} #ensure y is in symbol table
+while(FALSE){} #ensure y is in symbol table
 y = y*2;
 print(y);
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/unary/matrix/replace_Infinity.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/unary/matrix/replace_Infinity.dml b/src/test/scripts/functions/unary/matrix/replace_Infinity.dml
index 233d771..28ef73e 100644
--- a/src/test/scripts/functions/unary/matrix/replace_Infinity.dml
+++ b/src/test/scripts/functions/unary/matrix/replace_Infinity.dml
@@ -21,6 +21,6 @@
 
 
 A = read($1, rows=$2, cols=$3, format="text");
-if(1==1){} #for replace test in mappers
+while(FALSE){} #for replace test in mappers
 C = replace(target=A, pattern=1/0, replacement=4711);
 write(C, $4, format="text");  
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/unary/matrix/replace_NInfinity.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/unary/matrix/replace_NInfinity.dml b/src/test/scripts/functions/unary/matrix/replace_NInfinity.dml
index 42a592d..b458bec 100644
--- a/src/test/scripts/functions/unary/matrix/replace_NInfinity.dml
+++ b/src/test/scripts/functions/unary/matrix/replace_NInfinity.dml
@@ -21,6 +21,6 @@
 
 
 A = read($1, rows=$2, cols=$3, format="text");
-if(1==1){} #for replace test in mappers
+while(FALSE){} #for replace test in mappers
 C = replace(target=A, pattern=-1/0, replacement=4711);
 write(C, $4, format="text");  
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/unary/matrix/replace_NaN.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/unary/matrix/replace_NaN.dml b/src/test/scripts/functions/unary/matrix/replace_NaN.dml
index edc815c..1ef0420 100644
--- a/src/test/scripts/functions/unary/matrix/replace_NaN.dml
+++ b/src/test/scripts/functions/unary/matrix/replace_NaN.dml
@@ -21,6 +21,6 @@
 
 
 A = read($1, rows=$2, cols=$3, format="text");
-if(1==1){} #for replace test in mappers
+while(FALSE){} #for replace test in mappers
 C = replace(target=A, pattern=0/0, replacement=4711);
 write(C, $4, format="text");  
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/updateinplace/updateinplace1.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/updateinplace/updateinplace1.dml b/src/test/scripts/functions/updateinplace/updateinplace1.dml
index 6d19ab2..2603f37 100644
--- a/src/test/scripts/functions/updateinplace/updateinplace1.dml
+++ b/src/test/scripts/functions/updateinplace/updateinplace1.dml
@@ -26,8 +26,8 @@ parfor (j in 1:m, log=DEBUG){
   A = matrix(3, rows=n, cols=1);
   i = 1
   while (i <= n){
-		if (1 == 1)
-			print("i = " + i + " j = " + j + " Sum(A) = " + sum(A));
+		print("i = " + i + " j = " + j + " Sum(A) = " + sum(A));
+		while(FALSE){}
 		A[i,1] = j*7+i;
 		i = i + 1
 	}

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/updateinplace/updateinplace10.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/updateinplace/updateinplace10.dml b/src/test/scripts/functions/updateinplace/updateinplace10.dml
index 0d3a99a..44cc104 100644
--- a/src/test/scripts/functions/updateinplace/updateinplace10.dml
+++ b/src/test/scripts/functions/updateinplace/updateinplace10.dml
@@ -28,11 +28,11 @@ parfor (j in 1:m, log=DEBUG){
   for (i in 1:n){
   		print("i = " + i + " j = " + j + " Sum(B) = " + sum(B));
 		A[i,1] = j*2+i;
-		if(1 == 1)
-			B = A
+		while(FALSE){}
+		B = A
 		A[i,2] = j*3+i;
-		if(1 == 1)
-			B = A
+		while(FALSE){}
+		B = A
 		A[i,3] = j*4+i;
 	}
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test_suites/java/org/apache/sysml/test/integration/functions/misc/ZPackageSuite.java
----------------------------------------------------------------------
diff --git a/src/test_suites/java/org/apache/sysml/test/integration/functions/misc/ZPackageSuite.java b/src/test_suites/java/org/apache/sysml/test/integration/functions/misc/ZPackageSuite.java
index 95ed276..52f71f8 100644
--- a/src/test_suites/java/org/apache/sysml/test/integration/functions/misc/ZPackageSuite.java
+++ b/src/test_suites/java/org/apache/sysml/test/integration/functions/misc/ZPackageSuite.java
@@ -57,6 +57,7 @@ import org.junit.runners.Suite;
 	RewriteFusedRandTest.class,
 	RewriteLoopVectorization.class,
 	RewriteMatrixMultChainOptTest.class,
+	RewriteMergeBlocksTest.class,
 	RewritePushdownSumBinaryMult.class,
 	RewritePushdownSumOnBinaryTest.class,
 	RewritePushdownUaggTest.class,


[4/4] systemml git commit: [SYSTEMML-1833] Fix codegen race conditions and cleanup robustness

Posted by mb...@apache.org.
[SYSTEMML-1833] Fix codegen race conditions and cleanup robustness

This patch fixes two codegen issues which led to failures on the ARIMA
and MDABivariate algorithms. In detail, this includes (1) a fix of race
conditions on variable name creation/usage in multi-threaded parfor
contexts with dynamic recompilation, and (2) a fix of cleanup robustness
for row-wise templates with partial unknowns (which led to selecting a
row template for column vectors and thus invalid generated source code).
Additionally, we now also avoid unnecessary dense allocations for empty
side vector inputs to row-wise templates because these are only used
through cell indexing or dot products. 

Furthermore, this also includes a cleanup of the DML and R scripts for
MDABivariate statistics (vectorized loops), which simplifies debugging
and improves the R performance of these tests by almost 2x.


Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/c170374e
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/c170374e
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/c170374e

Branch: refs/heads/master
Commit: c170374e7fb2c709ac07b00caa9536c2da7e6987
Parents: 4b81d0d
Author: Matthias Boehm <mb...@gmail.com>
Authored: Wed Aug 9 13:51:38 2017 -0700
Committer: Matthias Boehm <mb...@gmail.com>
Committed: Wed Aug 9 13:52:53 2017 -0700

----------------------------------------------------------------------
 .../sysml/hops/codegen/SpoofCompiler.java       | 19 ++++---
 .../apache/sysml/hops/codegen/cplan/CNode.java  |  4 --
 .../sysml/hops/codegen/cplan/CNodeCell.java     |  2 +-
 .../hops/codegen/cplan/CNodeOuterProduct.java   |  2 +-
 .../hops/codegen/template/TemplateCell.java     |  2 +-
 .../sysml/runtime/codegen/SpoofOperator.java    | 10 ++--
 .../applications/MDABivariateStatsTest.java     |  1 +
 .../functions/codegen/AlgorithmARIMA.java       | 52 ++++++++++++++++++++
 .../functions/codegen/AlgorithmMDABivar.java    | 52 ++++++++++++++++++++
 .../applications/mdabivar/MDABivariateStats.R   | 35 +++++--------
 .../applications/mdabivar/MDABivariateStats.dml | 26 +++-------
 .../functions/codegen/ZPackageSuite.java        |  2 +
 12 files changed, 147 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/c170374e/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java b/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
index 5029802..d5c9618 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/SpoofCompiler.java
@@ -704,15 +704,18 @@ public class SpoofCompiler
 					}
 			}
 			
-			//remove spurious lookups on main input of cell template
-			if( tpl instanceof CNodeCell || tpl instanceof CNodeOuterProduct ) {
-				CNodeData in1 = (CNodeData)tpl.getInput().get(0);
-				rFindAndRemoveLookup(tpl.getOutput(), in1);
-			}
-			else if( tpl instanceof CNodeMultiAgg ) {
-				CNodeData in1 = (CNodeData)tpl.getInput().get(0);
+			//remove invalid lookups on main input (all templates)
+			CNodeData in1 = (CNodeData)tpl.getInput().get(0);
+			if( tpl instanceof CNodeMultiAgg )
 				rFindAndRemoveLookupMultiAgg((CNodeMultiAgg)tpl, in1);
-			}
+			else
+				rFindAndRemoveLookup(tpl.getOutput(), in1);
+			
+			//remove invalid row templates (e.g., due to partial unknowns)
+			if( tpl instanceof CNodeRow && (in1.getNumCols() == 1
+				|| (((CNodeRow)tpl).getRowType()==RowType.NO_AGG
+					&& tpl.getOutput().getDataType().isScalar())) )
+				cplans2.remove(e.getKey());
 			
 			//remove cplan w/ single op and w/o agg
 			if( (tpl instanceof CNodeCell && ((CNodeCell)tpl).getCellType()==CellType.NO_AGG

http://git-wip-us.apache.org/repos/asf/systemml/blob/c170374e/src/main/java/org/apache/sysml/hops/codegen/cplan/CNode.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/codegen/cplan/CNode.java b/src/main/java/org/apache/sysml/hops/codegen/cplan/CNode.java
index 1f91697..ff9103e 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/cplan/CNode.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/cplan/CNode.java
@@ -75,10 +75,6 @@ public abstract class CNode
 		return _genVar; 
 	}
 	
-	protected static String getCurrentVarName() {
-		return "TMP"+(_seqVar.getCurrentID()-1);
-	}
-	
 	public String getVarname() {
 		return _genVar;
 	}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c170374e/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeCell.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeCell.java b/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeCell.java
index 36cf56f..dd3806d 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeCell.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeCell.java
@@ -118,7 +118,7 @@ public class CNodeCell extends CNodeTpl
 		tmp = tmp.replace("%BODY_dense%", tmpDense);
 		
 		//return last TMP
-		tmp = tmp.replace("%OUT%", getCurrentVarName());
+		tmp = tmp.replace("%OUT%", _output.getVarname());
 		
 		//replace meta data information
 		tmp = tmp.replace("%TYPE%", getCellType().name());

http://git-wip-us.apache.org/repos/asf/systemml/blob/c170374e/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeOuterProduct.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeOuterProduct.java b/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeOuterProduct.java
index 90917f8..b06e9b9 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeOuterProduct.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/cplan/CNodeOuterProduct.java
@@ -83,7 +83,7 @@ public class CNodeOuterProduct extends CNodeTpl
 		else {
 			tmp = tmp.replace("%BODY_dense%", "");
 			tmp = tmp.replace("%BODY_cellwise%", tmpDense);
-			tmp = tmp.replace("%OUT_cellwise%", getCurrentVarName());
+			tmp = tmp.replace("%OUT_cellwise%", _output.getVarname());
 		}
 		//replace size information
 		tmp = tmp.replace("%LEN%", "len");

http://git-wip-us.apache.org/repos/asf/systemml/blob/c170374e/src/main/java/org/apache/sysml/hops/codegen/template/TemplateCell.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/codegen/template/TemplateCell.java b/src/main/java/org/apache/sysml/hops/codegen/template/TemplateCell.java
index b781fd8..c9d97b9 100644
--- a/src/main/java/org/apache/sysml/hops/codegen/template/TemplateCell.java
+++ b/src/main/java/org/apache/sysml/hops/codegen/template/TemplateCell.java
@@ -275,7 +275,7 @@ public class TemplateCell extends TemplateBase
 	}
 	
 	protected static boolean isValidOperation(Hop hop) 
-	{	
+	{
 		//prepare indicators for binary operations
 		boolean isBinaryMatrixScalar = false;
 		boolean isBinaryMatrixVector = false;

http://git-wip-us.apache.org/repos/asf/systemml/blob/c170374e/src/main/java/org/apache/sysml/runtime/codegen/SpoofOperator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/codegen/SpoofOperator.java b/src/main/java/org/apache/sysml/runtime/codegen/SpoofOperator.java
index e302012..cff640c 100644
--- a/src/main/java/org/apache/sysml/runtime/codegen/SpoofOperator.java
+++ b/src/main/java/org/apache/sysml/runtime/codegen/SpoofOperator.java
@@ -93,9 +93,13 @@ public abstract class SpoofOperator implements Serializable
 			if( denseOnly && (in.isInSparseFormat() || !in.isAllocated()) ) {
 				//convert empty or sparse to dense temporary block (note: we don't do
 				//this in place because this block might be used by multiple threads)
-				b[i-offset] = new SideInput(DataConverter.convertToDoubleVector(in), null, clen);
-				LOG.warn(getClass().getName()+": Converted "+in.getNumRows()+"x"+in.getNumColumns()+
-					", nnz="+in.getNonZeros()+" sideways input matrix from sparse to dense.");	
+				if( in.getNumColumns()==1 && in.isEmptyBlock(false) ) //dense empty
+					b[i-offset] = new SideInput(null, null, clen);
+				else {
+					b[i-offset] = new SideInput(DataConverter.convertToDoubleVector(in), null, clen);
+					LOG.warn(getClass().getName()+": Converted "+in.getNumRows()+"x"+in.getNumColumns()+
+						", nnz="+in.getNonZeros()+" sideways input matrix from sparse to dense.");	
+				}
 			}
 			else if( in.isInSparseFormat() && in.isAllocated() ) {
 				b[i-offset] = new SideInput(null, in, clen);

http://git-wip-us.apache.org/repos/asf/systemml/blob/c170374e/src/test/java/org/apache/sysml/test/integration/applications/MDABivariateStatsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/sysml/test/integration/applications/MDABivariateStatsTest.java b/src/test/java/org/apache/sysml/test/integration/applications/MDABivariateStatsTest.java
index 3b38504..f635241 100644
--- a/src/test/java/org/apache/sysml/test/integration/applications/MDABivariateStatsTest.java
+++ b/src/test/java/org/apache/sysml/test/integration/applications/MDABivariateStatsTest.java
@@ -72,6 +72,7 @@ public abstract class MDABivariateStatsTest extends AutomatedTestBase
 		if (scriptType == ScriptType.PYDML) {
 			proArgs.add("-python");
 		}
+		proArgs.add("-stats");
 		proArgs.add("-args");
 		proArgs.add(input("X"));
 		proArgs.add(Integer.toString(label_index));

http://git-wip-us.apache.org/repos/asf/systemml/blob/c170374e/src/test/java/org/apache/sysml/test/integration/functions/codegen/AlgorithmARIMA.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/sysml/test/integration/functions/codegen/AlgorithmARIMA.java b/src/test/java/org/apache/sysml/test/integration/functions/codegen/AlgorithmARIMA.java
new file mode 100644
index 0000000..248eb82
--- /dev/null
+++ b/src/test/java/org/apache/sysml/test/integration/functions/codegen/AlgorithmARIMA.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysml.test.integration.functions.codegen;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.File;
+
+import org.apache.sysml.test.integration.applications.ArimaTest;
+
+@RunWith(value = Parameterized.class)
+public class AlgorithmARIMA extends ArimaTest 
+{
+	private final static String LOCAL_TEST_DIR = "functions/codegen/";
+	private final static String TEST_CONF = "SystemML-config-codegen.xml";
+	private final static File   TEST_CONF_FILE = new File(SCRIPT_DIR + LOCAL_TEST_DIR, TEST_CONF);
+	
+	public AlgorithmARIMA(int m, int p, int d, int q, int P, int D, int Q, int s, int include_mean, int useJacobi) {
+		super(m, p, d, q, P, D, Q, s, include_mean, useJacobi);
+		TEST_CLASS_DIR = TEST_DIR + AlgorithmARIMA.class.getSimpleName() + "/";
+	}
+
+	@Test
+	public void testArimaDml() {
+		testArima(ScriptType.DML);
+	}
+	
+	@Override
+	protected File getConfigTemplateFile() {
+		System.out.println("This test case overrides default configuration with " + TEST_CONF_FILE.getPath());
+		return TEST_CONF_FILE;
+	}
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c170374e/src/test/java/org/apache/sysml/test/integration/functions/codegen/AlgorithmMDABivar.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/sysml/test/integration/functions/codegen/AlgorithmMDABivar.java b/src/test/java/org/apache/sysml/test/integration/functions/codegen/AlgorithmMDABivar.java
new file mode 100644
index 0000000..9477234
--- /dev/null
+++ b/src/test/java/org/apache/sysml/test/integration/functions/codegen/AlgorithmMDABivar.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysml.test.integration.functions.codegen;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.io.File;
+
+import org.apache.sysml.test.integration.applications.MDABivariateStatsTest;
+
+@RunWith(value = Parameterized.class)
+public class AlgorithmMDABivar extends MDABivariateStatsTest 
+{
+	private final static String LOCAL_TEST_DIR = "functions/codegen/";
+	private final static String TEST_CONF = "SystemML-config-codegen.xml";
+	private final static File   TEST_CONF_FILE = new File(SCRIPT_DIR + LOCAL_TEST_DIR, TEST_CONF);
+	
+	public AlgorithmMDABivar(int n, int m, int li, int lml) {
+		super(n, m, li, lml);
+		TEST_CLASS_DIR = TEST_DIR + AlgorithmMDABivar.class.getSimpleName() + "/";
+	}
+
+	@Test
+	public void testMDABivariateStatsDml() {
+		testMDABivariateStats(ScriptType.DML);
+	}
+	
+	@Override
+	protected File getConfigTemplateFile() {
+		System.out.println("This test case overrides default configuration with " + TEST_CONF_FILE.getPath());
+		return TEST_CONF_FILE;
+	}
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c170374e/src/test/scripts/applications/mdabivar/MDABivariateStats.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/applications/mdabivar/MDABivariateStats.R b/src/test/scripts/applications/mdabivar/MDABivariateStats.R
index 1844bbb..92605ad 100644
--- a/src/test/scripts/applications/mdabivar/MDABivariateStats.R
+++ b/src/test/scripts/applications/mdabivar/MDABivariateStats.R
@@ -101,19 +101,19 @@ args <- commandArgs(TRUE)
 library(Matrix)
 
 # input data set
-D = readMM(paste(args[1], "X.mtx", sep=""));
+D = as.matrix(readMM(paste(args[1], "X.mtx", sep="")));
 
 # label attr id (must be a valid index > 0)  
 label_index = as.integer(args[2])
 
 # feature attributes, column vector of indices
-feature_indices = readMM(paste(args[1], "feature_indices.mtx", sep="")) 
+feature_indices = as.matrix(readMM(paste(args[1], "feature_indices.mtx", sep=""))) 
 
 # can be either 1 (scale) or 0 (categorical)
 label_measurement_level = as.integer(args[3]) 
 
 # measurement levels for features, 0/1 column vector
-feature_measurement_levels = readMM(paste(args[1], "feature_measurement_levels.mtx", sep="")) 
+feature_measurement_levels = as.matrix(readMM(paste(args[1], "feature_measurement_levels.mtx", sep=""))) 
 
 sz = ncol(D)
 
@@ -180,9 +180,7 @@ featureSTDs = matrix(0, sz, maxNumberOfGroups)
 
 if(label_measurement_level == 0){
 	featureCounts[label_index,1:length(distinct_label_values)] = distinct_label_values
-	for(i2 in 1:length(distinct_label_values)){
-		featureValues[label_index,i2] = i2-labelCorrection
-	}
+	featureValues[label_index,1:length(distinct_label_values)] = t(seq(1,length(distinct_label_values))-labelCorrection);
 }
 
 for(i3 in 1:nrow(feature_indices)){
@@ -209,28 +207,19 @@ for(i3 in 1:nrow(feature_indices)){
 			
 		  sz3 = nrow(contingencyTable)*ncol(contingencyTable)
 			
-		  contingencyTableCounts = matrix(0, 1, sz3)
-		  contingencyTableLabelValues = matrix(0, 1, sz3)
-		  contingencyTableFeatureValues = matrix(0, 1, sz3)
+			tmpLV = (seq(1,nrow(contingencyTable)) %*% matrix(1,1,ncol(contingencyTable))) - labelCorrection;
+			tmpFV = (matrix(1,nrow(contingencyTable),1) %*% t(seq(1,ncol(contingencyTable)))) - featureCorrection;
+			contingencyTableLabelValues = matrix(tmpLV, 1, sz3, byrow=TRUE);
+			contingencyTableFeatureValues = matrix(tmpFV, 1, sz3, byrow=TRUE);
 			
-            	  for(i4 in 1:nrow(contingencyTable)){
-		  	 for(j in 1:ncol(contingencyTable)){
-					#get rid of this, see *1 below
-					contingencyTableCounts[1, ncol(contingencyTable)*(i4-1)+j] = contingencyTable[i4,j]
-					
-					contingencyTableLabelValues[1, ncol(contingencyTable)*(i4-1)+j] = i4-labelCorrection
-					contingencyTableFeatureValues[1, ncol(contingencyTable)*(i4-1)+j] = j-featureCorrection 
-				}
-			}
+			contingencyTableCounts = matrix(contingencyTable, 1, sz3, byrow=TRUE);
 			contingencyTablesCounts[feature_index2,1:sz3] = contingencyTableCounts
             
 			contingencyTablesLabelValues[feature_index2,1:sz3] = contingencyTableLabelValues
 			contingencyTablesFeatureValues[feature_index2,1:sz3] = contingencyTableFeatureValues
 			
 			featureCounts[feature_index2,1:length(colMarginals)] = colMarginals
-			for(i5 in 1:length(colMarginals)){
-				featureValues[feature_index2,i5] = i5-featureCorrection
-			}
+			featureValues[feature_index2,1:length(colMarginals)] = t(seq(1,length(colMarginals)) - featureCorrection);
 		}else{
 			# label is scale, feature is categorical
 			tests[feature_index2,1] = 2
@@ -243,9 +232,7 @@ for(i3 in 1:nrow(feature_indices)){
 
 			stats[feature_index2,1] = pVal
 			featureCounts[feature_index2,1:nrow(frequencies)] = t(frequencies)
-			for(i6 in 1:nrow(frequencies)){
-				featureValues[feature_index2,i6] = i6 - featureCorrection
-			}
+			featureValues[feature_index2,1:nrow(frequencies)] = t(seq(1,nrow(frequencies)) - featureCorrection)
 			featureMeans[feature_index2,1:nrow(means)] = t(means)
 			featureSTDs[feature_index2,1:nrow(variances)] = t(sqrt(variances))
 		}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c170374e/src/test/scripts/applications/mdabivar/MDABivariateStats.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/applications/mdabivar/MDABivariateStats.dml b/src/test/scripts/applications/mdabivar/MDABivariateStats.dml
index faf29b6..61ec7f2 100644
--- a/src/test/scripts/applications/mdabivar/MDABivariateStats.dml
+++ b/src/test/scripts/applications/mdabivar/MDABivariateStats.dml
@@ -101,9 +101,7 @@ featureSTDs = matrix(0, rows=sz, cols=maxNumberOfGroups)
 
 if(label_measurement_level == 0){
 	featureCounts[label_index,1:nrow(distinct_label_values)] = t(distinct_label_values)
-	parfor(i2 in 1:nrow(distinct_label_values)){
-		featureValues[label_index,i2] = i2-labelCorrection
-	}
+	featureValues[label_index,1:nrow(distinct_label_values)] = t(seq(1,nrow(distinct_label_values))-labelCorrection);
 }
 
 parfor(i3 in 1:nrow(feature_indices), check=0){
@@ -125,34 +123,26 @@ parfor(i3 in 1:nrow(feature_indices), check=0){
 			sz3 = nrow(contingencyTable)*ncol(contingencyTable)
 			while(FALSE){}
 			
-			contingencyTableLabelValues = matrix(0, rows=1, cols=sz3)
-			contingencyTableFeatureValues = matrix(0, rows=1, cols=sz3)
+			tmpLV = (seq(1,nrow(contingencyTable)) %*% matrix(1,1,ncol(contingencyTable))) - labelCorrection;
+			tmpFV = (matrix(1,nrow(contingencyTable),1) %*% t(seq(1,ncol(contingencyTable)))) - featureCorrection;
+			contingencyTableLabelValues = matrix(tmpLV, rows=1, cols=sz3)
+			contingencyTableFeatureValues = matrix(tmpFV, rows=1, cols=sz3)
 			
-            parfor(i4 in 1:nrow(contingencyTable), check=0){
-				parfor(j in 1:ncol(contingencyTable), check=0){
-					contingencyTableLabelValues[1, ncol(contingencyTable)*(i4-1)+j] = i4-labelCorrection
-					contingencyTableFeatureValues[1, ncol(contingencyTable)*(i4-1)+j] = j-featureCorrection 
-				}
-			}
 			contingencyTableCounts = matrix(contingencyTable, rows=1, cols=sz3, byrow=TRUE)
-            contingencyTablesCounts[feature_index2,1:sz3] = contingencyTableCounts
+			contingencyTablesCounts[feature_index2,1:sz3] = contingencyTableCounts
             
 			contingencyTablesLabelValues[feature_index2,1:sz3] = contingencyTableLabelValues
 			contingencyTablesFeatureValues[feature_index2,1:sz3] = contingencyTableFeatureValues
 			
 			featureCounts[feature_index2,1:ncol(colMarginals)] = colMarginals
-			parfor(i5 in 1:ncol(colMarginals), check=0){
-				featureValues[feature_index2,i5] = i5-featureCorrection
-			}
+			featureValues[feature_index2,1:ncol(colMarginals)] = t(seq(1,ncol(colMarginals)) - featureCorrection);
 		}else{
 			# label is scale, feature is categorical
 			tests[feature_index2,1] = 2
 			[pVal, frequencies, means, variances] = bivar_sc(labels, feature)
 			stats[feature_index2,1] = pVal
 			featureCounts[feature_index2,1:nrow(frequencies)] = t(frequencies)
-			parfor(i6 in 1:nrow(frequencies), check=0){
-				featureValues[feature_index2,i6] = i6 - featureCorrection
-			}
+			featureValues[feature_index2,1:nrow(frequencies)] = t(seq(1,nrow(frequencies)) - featureCorrection)
 			featureMeans[feature_index2,1:nrow(means)] = t(means)
 			featureSTDs[feature_index2,1:nrow(variances)] = t(sqrt(variances))
 		}

http://git-wip-us.apache.org/repos/asf/systemml/blob/c170374e/src/test_suites/java/org/apache/sysml/test/integration/functions/codegen/ZPackageSuite.java
----------------------------------------------------------------------
diff --git a/src/test_suites/java/org/apache/sysml/test/integration/functions/codegen/ZPackageSuite.java b/src/test_suites/java/org/apache/sysml/test/integration/functions/codegen/ZPackageSuite.java
index a9310b3..3b24fcc 100644
--- a/src/test_suites/java/org/apache/sysml/test/integration/functions/codegen/ZPackageSuite.java
+++ b/src/test_suites/java/org/apache/sysml/test/integration/functions/codegen/ZPackageSuite.java
@@ -26,10 +26,12 @@ import org.junit.runners.Suite;
  *  won't run two of them at once. */
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
+	AlgorithmARIMA.class,
 	AlgorithmGLM.class,
 	AlgorithmKMeans.class,
 	AlgorithmL2SVM.class,
 	AlgorithmLinregCG.class,
+	AlgorithmMDABivar.class,
 	AlgorithmMLogreg.class,
 	AlgorithmMSVM.class,
 	AlgorithmPNMF.class,


[3/4] systemml git commit: [SYSTEMML-1828, 1832] New rewrite for merging statement block sequences

Posted by mb...@apache.org.
[SYSTEMML-1828,1832] New rewrite for merging statement block sequences

This patch introduces a new statement block rewrite for merging DAGs of
subsequent last-level statement blocks. After constant folding and the
removal of unnecessary branches, we often end up with such sequences of
statement blocks. Since many rewrites and operator fusion work on the
granularity of individual DAGs, these unnecessary DAG cuts cause missed
optimization opportunities, especially in the context of operator fusion
(i.e., codegen). We now merge such sequences in awareness of rewrites
that explicitly split DAGs (to create recompilation points).

Apart from the new merge rewrite, this patch also fixes the IPA rewrite
pass that applies static rewrites per IPA round. The repeated
application of the statement block rewrite for injecting spark
checkpoints for variables used read-only in loops introduced redundant
statement blocks and checkpoints. The IPA rewrite pass now explicitly
excludes this rewrite.

Additionally, this patch also modifies the related tests to use
'while(FALSE){}' instead of 'if(1==1){}' as a DAG cut, and fixes some
minor compilation issues that showed up due to the increases
optimization scope.

Overall, there are many scripts and patterns that benefit from these
changes. For example, on 1 epoch of lenet w/ codegen, this patch
improved end-to-end performance from 328s to 297s due to increased
fusion opportunities and fewer compiled spark instructions (70 vs 82).


Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/4b81d0dd
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/4b81d0dd
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/4b81d0dd

Branch: refs/heads/master
Commit: 4b81d0dda6583f0ae96eaa7aa5832005ae5fa8a9
Parents: 0221fbc
Author: Matthias Boehm <mb...@gmail.com>
Authored: Mon Aug 7 22:21:32 2017 -0700
Committer: Matthias Boehm <mb...@gmail.com>
Committed: Wed Aug 9 13:52:51 2017 -0700

----------------------------------------------------------------------
 docs/dml-language-reference.md                  |   2 +-
 projects/breast_cancer/MachineLearning.ipynb    |   2 +-
 scripts/nn/test/test.dml                        |   2 +-
 .../hops/ipa/IPAPassApplyStaticHopRewrites.java |   5 +
 .../sysml/hops/rewrite/HopRewriteUtils.java     |  13 ++
 .../sysml/hops/rewrite/ProgramRewriter.java     |  59 ++++---
 .../RewriteAlgebraicSimplificationStatic.java   |   8 +-
 .../rewrite/RewriteForLoopVectorization.java    |  18 +-
 .../RewriteInjectSparkLoopCheckpointing.java    |  26 +--
 .../RewriteMarkLoopVariablesUpdateInPlace.java  |  19 +-
 .../hops/rewrite/RewriteMergeBlockSequence.java | 174 +++++++++++++++++++
 .../RewriteRemoveUnnecessaryBranches.java       |  10 +-
 .../RewriteSplitDagDataDependentOperators.java  |  15 +-
 .../rewrite/RewriteSplitDagUnknownCSVRead.java  |  16 +-
 .../hops/rewrite/StatementBlockRewriteRule.java |  22 ++-
 .../java/org/apache/sysml/lops/compile/Dag.java |  14 +-
 .../sysml/parser/BuiltinFunctionExpression.java |   2 +-
 .../org/apache/sysml/parser/DMLTranslator.java  |   7 +-
 .../sysml/parser/LiveVariableAnalysis.java      |  18 +-
 .../org/apache/sysml/parser/StatementBlock.java |   9 +
 .../org/apache/sysml/parser/VariableSet.java    |  55 +++---
 .../controlprogram/ParForProgramBlock.java      |   2 +-
 .../functions/misc/RewriteMergeBlocksTest.java  |  79 +++++++++
 .../integration/mlcontext/MLContextTest.java    |   2 +-
 .../scripts/applications/ctableStats/ctci.dml   |   6 +-
 .../applications/ctableStats/ctci_odds.dml      |   5 +-
 src/test/scripts/applications/id3/id3.dml       |  33 ++--
 .../applications/mdabivar/MDABivariateStats.dml |   7 +-
 .../validation/CV_LogisticRegression.dml        |  37 +---
 .../validation/CV_MultiClassSVM.sasha.dml       |   6 +-
 .../functions/codegen/SumAdditionChain.dml      |   2 +-
 .../functions/codegen/SumProductChain.dml       |   2 +-
 .../functions/codegen/cellwisetmpl15.dml        |   2 +-
 .../functions/codegen/cellwisetmpl16.dml        |   2 +-
 .../scripts/functions/codegen/cellwisetmpl7.dml |   2 +-
 .../scripts/functions/codegen/cellwisetmpl8.R   |   1 -
 .../scripts/functions/codegen/cellwisetmpl8.dml |   2 +-
 .../scripts/functions/codegen/miscPattern1.dml  |   4 +-
 .../scripts/functions/codegen/miscPattern2.dml  |   2 +-
 .../functions/codegen/multiAggPattern7.dml      |   2 +-
 .../functions/codegen/rowAggPattern17.dml       |   4 +-
 .../functions/codegen/rowAggPattern19.dml       |   2 +-
 .../functions/codegen/rowAggPattern23.dml       |   4 +-
 .../functions/codegen/rowAggPattern24.dml       |   2 +-
 .../functions/codegen/rowAggPattern25.dml       |   2 +-
 .../functions/codegen/rowAggPattern26.dml       |   2 +-
 .../functions/codegen/rowAggPattern27.dml       |   2 +-
 .../functions/codegen/rowAggPattern28.dml       |   2 +-
 .../functions/codegen/rowAggPattern29.dml       |   2 +-
 .../functions/codegen/rowAggPattern30.dml       |   2 +-
 .../codegen/wSparseUnsafeOuterProduct.dml       |   2 +-
 src/test/scripts/functions/codegen/wcemm.dml    |   2 +-
 src/test/scripts/functions/codegen/wdivmm.dml   |   2 +-
 .../scripts/functions/codegen/wdivmmRight.dml   |   2 +-
 .../codegen/wdivmmRightNotranspose.dml          |   2 +-
 .../functions/codegen/wdivmmTransposeOut.dml    |   2 +-
 .../scripts/functions/codegen/wdivmmbasic.dml   |   2 +-
 src/test/scripts/functions/codegen/wsigmoid.dml |   2 +-
 .../scripts/functions/frame/FrameFunction.dml   |   2 +-
 .../functions/frame/FrameMetaReadWrite.dml      |   2 +-
 .../functions/frame/FrameSchemaRead1.dml        |   2 +-
 .../functions/frame/FrameSchemaRead2.dml        |   2 +-
 .../functions/indexing/RowBatchIndexingTest.dml |   2 +-
 ...onstantFoldingScalarVariablePropagation1.dml |   4 +-
 ...onstantFoldingScalarVariablePropagation2.dml |   4 +-
 .../functions/misc/IPANnzPropagation1.dml       |   2 +-
 .../functions/misc/IPANnzPropagation2.dml       |   2 +-
 .../functions/misc/ReadAfterWriteMatrix2.dml    |   2 +-
 .../functions/misc/ReadAfterWriteScalar2.dml    |   2 +-
 .../misc/RewriteCSETransposeScalarMult.dml      |   4 +-
 .../misc/RewriteCSETransposeScalarPow.dml       |   4 +-
 .../misc/RewriteFuseBinaryOpChainTest1.dml      |   2 +-
 .../misc/RewriteFuseBinaryOpChainTest2.dml      |   2 +-
 .../misc/RewriteFuseBinaryOpChainTest3.dml      |   2 +-
 .../misc/RewriteFuseBinaryOpChainTest4.dml      |   2 +-
 .../scripts/functions/misc/RewriteFusedRand.dml |   2 +-
 .../functions/misc/RewriteMergeFunctionCut.R    |  36 ++++
 .../functions/misc/RewriteMergeFunctionCut.dml  |  38 ++++
 .../scripts/functions/misc/RewriteMergeIfCut.R  |  35 ++++
 .../functions/misc/RewriteMergeIfCut.dml        |  31 ++++
 .../misc/RewritePushdownSumBinaryMult.dml       |   2 +-
 .../misc/RewritePushdownSumBinaryMult2.dml      |   2 +-
 .../scripts/functions/misc/dt_change_4c.dml     |   2 +-
 .../scripts/functions/misc/dt_change_4d.dml     |   2 +-
 .../scripts/functions/misc/dt_change_4e.dml     |   2 +-
 .../scripts/functions/misc/dt_change_4f.dml     |   2 +-
 .../functions/misc/functionNoInlining.dml       |  10 +-
 src/test/scripts/functions/parfor/parfor49b.dml |   2 +-
 .../parfor_cdatapartition_leftindexing.dml      |   2 +-
 .../parfor_rdatapartition_leftindexing.dml      |   2 +-
 .../quaternary/WeightedDivMM4MultMinusLeft.dml  |   2 +-
 .../quaternary/WeightedDivMM4MultMinusRight.dml |   2 +-
 .../scripts/functions/recompile/append_nnz.dml  |   3 +-
 .../recompile/constant_propagation_if.R         |   8 +-
 .../recompile/constant_propagation_sb.R         |   9 -
 .../functions/recompile/if_recompile_sparse.dml |   5 +-
 .../functions/recompile/multiple_reads.R        |   9 +-
 .../recompile/remove_empty_potpourri2.dml       |   2 +-
 .../recompile/remove_empty_potpourri3.dml       |   4 +-
 .../recompile/remove_empty_potpourri4.dml       |   4 +-
 .../recompile/rewrite_mapmultchain1.dml         |   4 +-
 .../recompile/rewrite_mapmultchain2.dml         |   4 +-
 src/test/scripts/functions/reorg/Order.dml      |   2 +-
 src/test/scripts/functions/reorg/OrderDyn.dml   |   2 +-
 .../functions/ternary/AAATernaryAggregateC.dml  |   2 +-
 .../functions/ternary/AAATernaryAggregateRC.dml |   2 +-
 .../functions/ternary/ABATernaryAggregateC.dml  |   2 +-
 .../functions/ternary/ABATernaryAggregateRC.dml |   2 +-
 .../functions/ternary/CTableSequenceLeft.dml    |   1 +
 .../functions/ternary/CTableSequenceRight.dml   |   1 +
 .../functions/ternary/TernaryAggregateC.dml     |   2 +-
 .../functions/ternary/TernaryAggregateRC.dml    |   2 +-
 .../functions/transform/FrameCSVReadWrite.dml   |   2 +-
 .../transform/TransformCSVFrameEncodeDecode.dml |   2 +-
 .../transform/TransformFrameEncodeApply.dml     |   2 +-
 .../transform/TransformFrameEncodeDecode.dml    |   2 +-
 .../functions/unary/matrix/PrintTest.dml        |   8 +-
 .../functions/unary/matrix/replace_Infinity.dml |   2 +-
 .../unary/matrix/replace_NInfinity.dml          |   2 +-
 .../functions/unary/matrix/replace_NaN.dml      |   2 +-
 .../functions/updateinplace/updateinplace1.dml  |   4 +-
 .../functions/updateinplace/updateinplace10.dml |   8 +-
 .../functions/misc/ZPackageSuite.java           |   1 +
 123 files changed, 744 insertions(+), 311 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/docs/dml-language-reference.md
----------------------------------------------------------------------
diff --git a/docs/dml-language-reference.md b/docs/dml-language-reference.md
index d5e200d..bd66a42 100644
--- a/docs/dml-language-reference.md
+++ b/docs/dml-language-reference.md
@@ -1782,7 +1782,7 @@ The following DML utilizes the `transformencode()` function.
     jspec = read("/user/ml/homes.tfspec_recode2.json", data_type="scalar", value_type="string");
     [X, M] = transformencode(target=F1, spec=jspec);
     print(toString(X));
-    if(1==1){}
+    while(FALSE){}
     print(toString(M));
 
 The transformed matrix X and output M are as follows.

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/projects/breast_cancer/MachineLearning.ipynb
----------------------------------------------------------------------
diff --git a/projects/breast_cancer/MachineLearning.ipynb b/projects/breast_cancer/MachineLearning.ipynb
index b27116f..1a423b7 100644
--- a/projects/breast_cancer/MachineLearning.ipynb
+++ b/projects/breast_cancer/MachineLearning.ipynb
@@ -683,7 +683,7 @@
    "source": [
     "# script = \"\"\"\n",
     "# f = function(matrix[double] X) return(matrix[double] Y) {\n",
-    "#   if (1==1) {}\n",
+    "#   while(FALSE){}\n",
     "#   a = as.scalar(rand(rows=1, cols=1))\n",
     "#   Y = X * a\n",
     "# }\n",

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/scripts/nn/test/test.dml
----------------------------------------------------------------------
diff --git a/scripts/nn/test/test.dml b/scripts/nn/test/test.dml
index e63639c..06f4632 100644
--- a/scripts/nn/test/test.dml
+++ b/scripts/nn/test/test.dml
@@ -599,7 +599,7 @@ max_pool2d = function() {
   for (padh in 0:3) {
     for (padw in 0:3) {
       print(" - Testing w/ padh="+padh+" & padw="+padw+".")
-      #if (1==1) {}  # force correct printing
+      #while(FALSE){}  # force correct printing
       #print("   - Testing forward")
       [out, Hout, Wout] = max_pool2d::forward(X, C, Hin, Win, Hf, Wf, stride, stride, padh, padw)
       [out_simple, Hout_simple, Wout_simple] = max_pool2d_simple::forward(X, C, Hin, Win, Hf, Wf,

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/hops/ipa/IPAPassApplyStaticHopRewrites.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/ipa/IPAPassApplyStaticHopRewrites.java b/src/main/java/org/apache/sysml/hops/ipa/IPAPassApplyStaticHopRewrites.java
index f436658..923259c 100644
--- a/src/main/java/org/apache/sysml/hops/ipa/IPAPassApplyStaticHopRewrites.java
+++ b/src/main/java/org/apache/sysml/hops/ipa/IPAPassApplyStaticHopRewrites.java
@@ -22,6 +22,7 @@ package org.apache.sysml.hops.ipa;
 
 import org.apache.sysml.hops.HopsException;
 import org.apache.sysml.hops.rewrite.ProgramRewriter;
+import org.apache.sysml.hops.rewrite.RewriteInjectSparkLoopCheckpointing;
 import org.apache.sysml.parser.DMLProgram;
 import org.apache.sysml.parser.LanguageException;
 
@@ -43,7 +44,11 @@ public class IPAPassApplyStaticHopRewrites extends IPAPass
 		throws HopsException
 	{
 		try {
+			//construct rewriter w/o checkpoint injection to avoid redundancy
 			ProgramRewriter rewriter = new ProgramRewriter(true, false);
+			rewriter.removeStatementBlockRewrite(RewriteInjectSparkLoopCheckpointing.class);
+			
+			//rewrite program hop dags and statement blocks
 			rewriter.rewriteProgramHopDAGs(prog);
 		} 
 		catch (LanguageException ex) {

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
index 3530142..351173f 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
@@ -622,6 +622,14 @@ public class HopRewriteUtils
 		return ternOp;
 	}
 	
+	public static DataOp createDataOp(String name, Hop input, DataOpTypes type) {
+		DataOp dop = new DataOp(name, input.getDataType(), input.getValueType(), input, type, null);
+		dop.setOutputBlocksizes(input.getRowsInBlock(), input.getColsInBlock());
+		copyLineNumbers(input, dop);
+		dop.refreshSizeInformation();
+		return dop;
+	}
+	
 	public static void setOutputParameters( Hop hop, long rlen, long clen, long brlen, long bclen, long nnz ) {
 		hop.setDim1( rlen );
 		hop.setDim2( clen );
@@ -846,6 +854,11 @@ public class HopRewriteUtils
 		return ret;
 	}
 	
+	public static boolean isData(Hop hop, DataOpTypes type) {
+		return hop instanceof DataOp
+			&& ((DataOp)hop).getDataOpType()==type;
+	}
+	
 	public static boolean isBinaryMatrixColVectorOperation(Hop hop) {
 		return hop instanceof BinaryOp 
 			&& hop.getInput().get(0).getDataType().isMatrix() && hop.getInput().get(1).getDataType().isMatrix()

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/hops/rewrite/ProgramRewriter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/ProgramRewriter.java b/src/main/java/org/apache/sysml/hops/rewrite/ProgramRewriter.java
index 7c4f861..82eff52 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/ProgramRewriter.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/ProgramRewriter.java
@@ -20,6 +20,7 @@
 package org.apache.sysml.hops.rewrite;
 
 import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -49,7 +50,7 @@ import org.apache.sysml.parser.WhileStatementBlock;
  * program. 
  * 
  */
-public class ProgramRewriter 
+public class ProgramRewriter
 {
 	private static final Log LOG = LogFactory.getLog(ProgramRewriter.class.getName());
 	
@@ -60,17 +61,15 @@ public class ProgramRewriter
 	private ArrayList<HopRewriteRule> _dagRuleSet = null;
 	private ArrayList<StatementBlockRewriteRule> _sbRuleSet = null;
 	
-	static{
+	static {
 		// for internal debugging only
 		if( LDEBUG ) {
 			Logger.getLogger("org.apache.sysml.hops.rewrite")
 				  .setLevel((Level) Level.DEBUG);
 		}
-		
 	}
 	
-	public ProgramRewriter()
-	{
+	public ProgramRewriter() {
 		// by default which is used during initial compile 
 		// apply all (static and dynamic) rewrites
 		this( true, true );
@@ -107,12 +106,14 @@ public class ProgramRewriter
 			_dagRuleSet.add( new RewriteInjectSparkPReadCheckpointing()          ); //dependency: reblock
 			
 			//add statement block rewrite rules
- 			if( OptimizerUtils.ALLOW_BRANCH_REMOVAL )			
+ 			if( OptimizerUtils.ALLOW_BRANCH_REMOVAL ) {
 				_sbRuleSet.add(  new RewriteRemoveUnnecessaryBranches()          ); //dependency: constant folding		
+				_sbRuleSet.add(  new RewriteMergeBlockSequence()                 ); //dependency: remove branches
+ 			}
  			if( OptimizerUtils.ALLOW_SPLIT_HOP_DAGS )
- 				_sbRuleSet.add(  new RewriteSplitDagUnknownCSVRead()             ); //dependency: reblock	
+ 				_sbRuleSet.add(  new RewriteSplitDagUnknownCSVRead()             ); //dependency: reblock, merge blocks	
  			if( ConfigurationManager.getCompilerConfigFlag(ConfigType.ALLOW_INDIVIDUAL_SB_SPECIFIC_OPS) )
- 				_sbRuleSet.add(  new RewriteSplitDagDataDependentOperators()     );
+ 				_sbRuleSet.add(  new RewriteSplitDagDataDependentOperators()     ); //dependency: merge blocks
  			if( OptimizerUtils.ALLOW_AUTO_VECTORIZATION )
 				_sbRuleSet.add(  new RewriteForLoopVectorization()               ); //dependency: reblock (reblockop)
  			_sbRuleSet.add( new RewriteInjectSparkLoopCheckpointing(true)        ); //dependency: reblock (blocksizes)
@@ -146,8 +147,7 @@ public class ProgramRewriter
 	 * 
 	 * @param rewrites the HOP rewrite rules
 	 */
-	public ProgramRewriter( HopRewriteRule... rewrites )
-	{
+	public ProgramRewriter( HopRewriteRule... rewrites ) {
 		//initialize HOP DAG rewrite ruleSet (with fixed rewrite order)
 		_dagRuleSet = new ArrayList<HopRewriteRule>();
 		for( HopRewriteRule rewrite : rewrites )
@@ -161,8 +161,7 @@ public class ProgramRewriter
 	 * 
 	 * @param rewrites the statement block rewrite rules
 	 */
-	public ProgramRewriter( StatementBlockRewriteRule... rewrites )
-	{
+	public ProgramRewriter( StatementBlockRewriteRule... rewrites ) {
 		//initialize HOP DAG rewrite ruleSet (with fixed rewrite order)
 		_dagRuleSet = new ArrayList<HopRewriteRule>();
 		
@@ -177,8 +176,7 @@ public class ProgramRewriter
 	 * @param hRewrites HOP rewrite rules
 	 * @param sbRewrites statement block rewrite rules
 	 */
-	public ProgramRewriter( ArrayList<HopRewriteRule> hRewrites, ArrayList<StatementBlockRewriteRule> sbRewrites )
-	{
+	public ProgramRewriter(ArrayList<HopRewriteRule> hRewrites, ArrayList<StatementBlockRewriteRule> sbRewrites) {
 		//initialize HOP DAG rewrite ruleSet (with fixed rewrite order)
 		_dagRuleSet = new ArrayList<HopRewriteRule>();
 		_dagRuleSet.addAll( hRewrites );
@@ -187,6 +185,14 @@ public class ProgramRewriter
 		_sbRuleSet.addAll( sbRewrites );
 	}
 	
+	public void removeHopRewrite(Class<? extends HopRewriteRule> clazz) {
+		_dagRuleSet.removeIf(r -> r.getClass().equals(clazz));
+	}
+	
+	public void removeStatementBlockRewrite(Class<? extends StatementBlockRewriteRule> clazz) {
+		_sbRuleSet.removeIf(r -> r.getClass().equals(clazz));
+	}
+	
 	public ProgramRewriteStatus rewriteProgramHopDAGs(DMLProgram dmlp) 
 		throws LanguageException, HopsException
 	{	
@@ -301,21 +307,23 @@ public class ProgramRewriter
 		return root;
 	}
 	
-	public ArrayList<StatementBlock> rewriteStatementBlocks( ArrayList<StatementBlock> sbs, ProgramRewriteStatus state ) 
+	public ArrayList<StatementBlock> rewriteStatementBlocks( ArrayList<StatementBlock> sbs, ProgramRewriteStatus status ) 
 		throws HopsException
 	{
 		//ensure robustness for calls from outside
-		if( state == null )
-			state = new ProgramRewriteStatus();
-				
+		if( status == null )
+			status = new ProgramRewriteStatus();
 		
-		ArrayList<StatementBlock> tmp = new ArrayList<StatementBlock>();
+		//apply rewrite rules to list of statement blocks
+		List<StatementBlock> sbList = sbs; 
+		for( StatementBlockRewriteRule r : _sbRuleSet ) {
+			sbList = r.rewriteStatementBlocks(sbList, status);
+		}
 		
 		//rewrite statement blocks (with potential expansion)
-		for( StatementBlock sb : sbs )
-			tmp.addAll( rewriteStatementBlock(sb, state) );
-		
-		//copy results into original collection
+		ArrayList<StatementBlock> tmp = new ArrayList<StatementBlock>();
+		for( StatementBlock sb : sbList )
+			tmp.addAll( rewriteStatementBlock(sb, status) );
 		sbs.clear();
 		sbs.addAll( tmp );
 		
@@ -362,9 +370,8 @@ public class ProgramRewriter
 			status.setInParforContext(prestatus);
 		}
 		
-		//apply rewrite rules
-		for( StatementBlockRewriteRule r : _sbRuleSet )
-		{
+		//apply rewrite rules to individual statement blocks
+		for( StatementBlockRewriteRule r : _sbRuleSet ) {
 			ArrayList<StatementBlock> tmp = new ArrayList<StatementBlock>();			
 			for( StatementBlock sbc : ret )
 				tmp.addAll( r.rewriteStatementBlock(sbc, status) );

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java
index 53359cc..63c6772 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java
@@ -1647,11 +1647,9 @@ public class RewriteAlgebraicSimplificationStatic extends HopRewriteRule
 				inputargs.put("cast", new LiteralOp(false));
 			
 				//create new hop
-				ParameterizedBuiltinOp pbop = new ParameterizedBuiltinOp("tmp", DataType.MATRIX, ValueType.DOUBLE, 
-						ParamBuiltinOp.REXPAND, inputargs);
-				pbop.setOutputBlocksizes(hi.getRowsInBlock(), hi.getColsInBlock());
-				pbop.refreshSizeInformation();
-		
+				ParameterizedBuiltinOp pbop = HopRewriteUtils
+					.createParameterizedBuiltinOp(trgt, inputargs, ParamBuiltinOp.REXPAND);
+				
 				//relink new hop into original position
 				HopRewriteUtils.replaceChildReference(parent, hi, pbop, pos);
 				hi = pbop;

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/hops/rewrite/RewriteForLoopVectorization.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteForLoopVectorization.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteForLoopVectorization.java
index 7154b36..fdcf96b 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteForLoopVectorization.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteForLoopVectorization.java
@@ -19,7 +19,8 @@
 
 package org.apache.sysml.hops.rewrite;
 
-import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 import org.apache.sysml.hops.AggUnaryOp;
 import org.apache.sysml.hops.BinaryOp;
@@ -49,17 +50,14 @@ import org.apache.sysml.parser.Expression.DataType;
  */
 public class RewriteForLoopVectorization extends StatementBlockRewriteRule
 {
-
 	private static final OpOp2[] MAP_SCALAR_AGGREGATE_SOURCE_OPS = new OpOp2[]{OpOp2.PLUS, OpOp2.MULT, OpOp2.MIN, OpOp2.MAX};
 	private static final AggOp[] MAP_SCALAR_AGGREGATE_TARGET_OPS = new AggOp[]{AggOp.SUM,  AggOp.PROD, AggOp.MIN, AggOp.MAX};
 	
 	
 	@Override
-	public ArrayList<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus state)
+	public List<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus state)
 		throws HopsException 
 	{
-		ArrayList<StatementBlock> ret = new ArrayList<StatementBlock>();
-		
 		if( sb instanceof ForStatementBlock )
 		{
 			ForStatementBlock fsb = (ForStatementBlock) sb;
@@ -96,9 +94,13 @@ public class RewriteForLoopVectorization extends StatementBlockRewriteRule
 		
 		//if no rewrite applied sb is the original for loop otherwise a last level statement block
 		//that includes the equivalent vectorized operations.
-		ret.add( sb );
-		
-		return ret;
+		return Arrays.asList(sb);
+	}
+	
+	@Override
+	public List<StatementBlock> rewriteStatementBlocks(List<StatementBlock> sbs, 
+			ProgramRewriteStatus sate) throws HopsException {
+		return sbs;
 	}
 	
 	private StatementBlock vectorizeScalarAggregate( StatementBlock sb, StatementBlock csb, Hop from, Hop to, Hop increment, String itervar ) 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/hops/rewrite/RewriteInjectSparkLoopCheckpointing.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteInjectSparkLoopCheckpointing.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteInjectSparkLoopCheckpointing.java
index 6b46ee2..1c59e6e 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteInjectSparkLoopCheckpointing.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteInjectSparkLoopCheckpointing.java
@@ -20,6 +20,8 @@
 package org.apache.sysml.hops.rewrite;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 import org.apache.sysml.hops.DataOp;
 import org.apache.sysml.hops.Hop;
@@ -47,21 +49,17 @@ public class RewriteInjectSparkLoopCheckpointing extends StatementBlockRewriteRu
 {
 	private boolean _checkCtx = false;
 	
-	public RewriteInjectSparkLoopCheckpointing(boolean checkParForContext)
-	{
+	public RewriteInjectSparkLoopCheckpointing(boolean checkParForContext) {
 		_checkCtx = checkParForContext;
 	}
 	
 	@Override
-	public ArrayList<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus status)
+	public List<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus status)
 		throws HopsException 
 	{
-		ArrayList<StatementBlock> ret = new ArrayList<StatementBlock>();
-		
-		if( !OptimizerUtils.isSparkExecutionMode() ) 
-		{
-			ret.add(sb); // nothing to do here
-			return ret; //return original statement block
+		if( !OptimizerUtils.isSparkExecutionMode() ) {
+			// nothing to do here, return original statement block
+			return Arrays.asList(sb);
 		}
 		
 		//1) We currently add checkpoint operations without information about the global program structure,
@@ -69,6 +67,7 @@ public class RewriteInjectSparkLoopCheckpointing extends StatementBlockRewriteRu
 		//2) Also, we do not take size information into account right now. This means that all candidates
 		//are checkpointed even if they are only used by CP operations.
 		
+		ArrayList<StatementBlock> ret = new ArrayList<>();
 		int blocksize = status.getBlocksize(); //block size set by reblock rewrite
 		
 		//apply rewrite for while, for, and parfor (the decision for parfor loop bodies is deferred until parfor
@@ -101,7 +100,7 @@ public class RewriteInjectSparkLoopCheckpointing extends StatementBlockRewriteRu
 					long dim2 = (dat instanceof IndexedIdentifier) ? ((IndexedIdentifier)dat).getOrigDim2() : dat.getDim2();
 					DataOp tread = new DataOp(var, DataType.MATRIX, ValueType.DOUBLE, DataOpTypes.TRANSIENTREAD, 
 							            dat.getFilename(), dim1, dim2, dat.getNnz(), blocksize, blocksize);
-					tread.setRequiresCheckpoint( true );
+					tread.setRequiresCheckpoint(true);
 					DataOp twrite = new DataOp(var, DataType.MATRIX, ValueType.DOUBLE, tread, DataOpTypes.TRANSIENTWRITE, null);
 					HopRewriteUtils.setOutputParameters(twrite, dim1, dim2, blocksize, blocksize, dat.getNnz());					
 					hops.add(twrite);
@@ -111,6 +110,7 @@ public class RewriteInjectSparkLoopCheckpointing extends StatementBlockRewriteRu
 				sb0.set_hops(hops);
 				sb0.setLiveIn(livein);
 				sb0.setLiveOut(liveout);
+				sb0.setSplitDag(true);
 				ret.add(sb0);
 				
 				//maintain rewrite status
@@ -123,4 +123,10 @@ public class RewriteInjectSparkLoopCheckpointing extends StatementBlockRewriteRu
 		
 		return ret;
 	}
+	
+	@Override
+	public List<StatementBlock> rewriteStatementBlocks(List<StatementBlock> sbs, 
+			ProgramRewriteStatus sate) throws HopsException {
+		return sbs;
+	}
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/hops/rewrite/RewriteMarkLoopVariablesUpdateInPlace.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteMarkLoopVariablesUpdateInPlace.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteMarkLoopVariablesUpdateInPlace.java
index 6e3621f..a61dd43 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteMarkLoopVariablesUpdateInPlace.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteMarkLoopVariablesUpdateInPlace.java
@@ -20,6 +20,8 @@
 package org.apache.sysml.hops.rewrite;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 import org.apache.sysml.api.DMLScript;
 import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
@@ -47,16 +49,14 @@ import org.apache.sysml.parser.Expression.DataType;
 public class RewriteMarkLoopVariablesUpdateInPlace extends StatementBlockRewriteRule
 {
 	@Override
-	public ArrayList<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus status)
+	public List<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus status)
 		throws HopsException 
 	{
-		ArrayList<StatementBlock> ret = new ArrayList<StatementBlock>();
-		
 		if( DMLScript.rtplatform == RUNTIME_PLATFORM.HADOOP
 			|| DMLScript.rtplatform == RUNTIME_PLATFORM.SPARK )
 		{
-			ret.add(sb); // nothing to do here
-			return ret; //return original statement block
+			// nothing to do here, return original statement block
+			return Arrays.asList(sb);
 		}
 		
 		if( sb instanceof WhileStatementBlock || sb instanceof ForStatementBlock ) //incl parfor 
@@ -86,8 +86,7 @@ public class RewriteMarkLoopVariablesUpdateInPlace extends StatementBlockRewrite
 		}
 			
 		//return modified statement block
-		ret.add(sb);
-		return ret;
+		return Arrays.asList(sb);
 	}
 	
 	private boolean rIsApplicableForUpdateInPlace( ArrayList<StatementBlock> sbs, String varname ) 
@@ -150,4 +149,10 @@ public class RewriteMarkLoopVariablesUpdateInPlace extends StatementBlockRewrite
 		
 		return validLix;
 	}
+	
+	@Override
+	public List<StatementBlock> rewriteStatementBlocks(List<StatementBlock> sbs, 
+			ProgramRewriteStatus sate) throws HopsException {
+		return sbs;
+	}
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/hops/rewrite/RewriteMergeBlockSequence.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteMergeBlockSequence.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteMergeBlockSequence.java
new file mode 100644
index 0000000..746e536
--- /dev/null
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteMergeBlockSequence.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysml.hops.rewrite;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.sysml.hops.FunctionOp;
+import org.apache.sysml.hops.Hop;
+import org.apache.sysml.hops.Hop.DataOpTypes;
+import org.apache.sysml.hops.HopsException;
+import org.apache.sysml.parser.ForStatementBlock;
+import org.apache.sysml.parser.FunctionStatementBlock;
+import org.apache.sysml.parser.IfStatementBlock;
+import org.apache.sysml.parser.StatementBlock;
+import org.apache.sysml.parser.VariableSet;
+import org.apache.sysml.parser.WhileStatementBlock;
+
+/**
+ * Rule: Simplify program structure by merging sequences of last-level
+ * statement blocks in order to create optimization opportunities.
+ * 
+ */
+public class RewriteMergeBlockSequence extends StatementBlockRewriteRule
+{
+	private ProgramRewriter rewriter = new ProgramRewriter(
+		new RewriteCommonSubexpressionElimination(true));
+	
+	@Override
+	public List<StatementBlock> rewriteStatementBlock(StatementBlock sb, 
+			ProgramRewriteStatus state) throws HopsException {
+		return Arrays.asList(sb);
+	}
+	
+	@Override
+	public List<StatementBlock> rewriteStatementBlocks(List<StatementBlock> sbs, 
+			ProgramRewriteStatus sate) throws HopsException 
+	{
+		if( sbs == null || sbs.isEmpty() )
+			return sbs;
+		
+		//execute binary merging iterations until fixpoint 
+		ArrayList<StatementBlock> tmpList = new ArrayList<>(sbs);
+		boolean merged = true;
+		while( merged ) {
+			merged = false;
+			for( int i=0; i<tmpList.size()-1; i++ ) {
+				StatementBlock sb1 = tmpList.get(i);
+				StatementBlock sb2 = tmpList.get(i+1);
+				if( isLastLevelStatementBlock(sb1) && isLastLevelStatementBlock(sb2) 
+					&& !hasFunctionOpRoot(sb1) && !sb1.isSplitDag() && !sb2.isSplitDag() 
+					&& sb2.getBeginLine()!=34 ) 
+				{
+					ArrayList<Hop> sb1Hops = sb1.get_hops();
+					ArrayList<Hop> sb2Hops = sb2.get_hops();
+					
+					//determine transient read inputs s2 
+					Hop.resetVisitStatus(sb2Hops);
+					HashMap<String,Hop> treads = new HashMap<>();
+					HashMap<String,Hop> twrites = new HashMap<>();
+					for( Hop root : sb2Hops )
+						rCollectTransientReadWrites(root, treads, twrites);
+					Hop.resetVisitStatus(sb2Hops);
+					
+					//merge hop dags of s1 and s2
+					Hop.resetVisitStatus(sb1Hops);
+					for( Hop root : sb1Hops ) {
+						//connect transient writes s1 and reads s2
+						if( HopRewriteUtils.isData(root, DataOpTypes.TRANSIENTWRITE) 
+							&& treads.containsKey(root.getName()) ) {
+							//rewire transient write and transient read
+							Hop tread = treads.get(root.getName());
+							Hop in = root.getInput().get(0);
+							for( Hop parent : new ArrayList<Hop>(tread.getParent()) )
+								HopRewriteUtils.replaceChildReference(parent, tread, in);
+							HopRewriteUtils.removeAllChildReferences(root);
+							//add transient write if necessary
+							if( !twrites.containsKey(root.getName()) 
+								&& sb2.liveOut().containsVariable(root.getName()) ) {
+								sb2Hops.add(HopRewriteUtils.createDataOp(
+									root.getName(), in, DataOpTypes.TRANSIENTWRITE));
+							}
+						}
+						//add remaining roots from s1 to s2
+						else if( !(HopRewriteUtils.isData(root, DataOpTypes.TRANSIENTWRITE)
+							&& twrites.containsKey(root.getName())) ) {
+							sb2Hops.add(root);
+						}
+					}
+					Hop.resetVisitStatus(sb2Hops);
+					
+					//run common-subexpression elimination
+					rewriter.rewriteHopDAGs(sb2Hops, new ProgramRewriteStatus());
+					
+					//modify live variable sets of s2
+					sb2.setLiveIn(sb1.liveIn()); //liveOut remains unchanged
+					sb2.setGen(VariableSet.minus(VariableSet.union(sb1.getGen(), sb2.getGen()), sb1.getKill()));
+					sb2.setKill(VariableSet.union(sb1.getKill(), sb2.getKill()));
+					sb2.setReadVariables(VariableSet.union(sb1.variablesRead(), sb2.variablesRead()));
+					sb2.setUpdatedVariables(VariableSet.union(sb1.variablesUpdated(), sb2.variablesUpdated()));
+					
+					LOG.debug("Applied mergeStatementBlockSequences "
+							+ "(blocks of lines "+sb1.getBeginLine()+"-"+sb1.getEndLine()
+							+" and "+sb2.getBeginLine()+"-"+sb2.getEndLine()+").");
+					
+					//modify line numbers of s2
+					sb2.setBeginLine(sb1.getBeginLine());
+					sb2.setBeginColumn(sb1.getBeginColumn());
+					
+					//remove sb1 from list of statement blocks
+					tmpList.remove(i);
+					merged = true;
+					break; //for
+				}
+			}
+		}
+		
+		return tmpList;
+	}
+	
+	private void rCollectTransientReadWrites(Hop current, HashMap<String, Hop> treads, HashMap<String, Hop> twrites) {
+		if( current.isVisited() )
+			return;
+		//process nodes recursively
+		for( Hop c : current.getInput() )
+			rCollectTransientReadWrites(c, treads, twrites);
+		//collect all transient reads
+		if( HopRewriteUtils.isData(current, DataOpTypes.TRANSIENTREAD) )
+			treads.put(current.getName(), current);
+		else if( HopRewriteUtils.isData(current, DataOpTypes.TRANSIENTWRITE) )
+			twrites.put(current.getName(), current);
+		else if( current instanceof FunctionOp ) {
+			for( String output : ((FunctionOp)current).getOutputVariableNames() )
+				twrites.put(output, null); //only name lookup
+		}
+		current.setVisited();
+	}
+	
+	private static boolean hasFunctionOpRoot(StatementBlock sb) 
+			throws HopsException {
+		if( sb == null || sb.get_hops() == null )
+			return false;
+		boolean ret = false;
+		for( Hop root : sb.get_hops() )
+			ret |= (root instanceof FunctionOp);
+		return ret;
+	}
+	
+	private static boolean isLastLevelStatementBlock(StatementBlock sb) {
+		return !((sb instanceof FunctionStatementBlock)
+			|| (sb instanceof WhileStatementBlock)
+			|| (sb instanceof IfStatementBlock)
+			|| (sb instanceof ForStatementBlock)); //incl parfor
+	}
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/hops/rewrite/RewriteRemoveUnnecessaryBranches.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteRemoveUnnecessaryBranches.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteRemoveUnnecessaryBranches.java
index fa99948..27e1dd3 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteRemoveUnnecessaryBranches.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteRemoveUnnecessaryBranches.java
@@ -20,6 +20,7 @@
 package org.apache.sysml.hops.rewrite;
 
 import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.sysml.hops.Hop;
 import org.apache.sysml.hops.HopsException;
@@ -36,9 +37,8 @@ import org.apache.sysml.parser.StatementBlock;
  */
 public class RewriteRemoveUnnecessaryBranches extends StatementBlockRewriteRule
 {
-
 	@Override
-	public ArrayList<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus state)
+	public List<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus state)
 		throws HopsException 
 	{
 		ArrayList<StatementBlock> ret = new ArrayList<StatementBlock>();
@@ -81,4 +81,10 @@ public class RewriteRemoveUnnecessaryBranches extends StatementBlockRewriteRule
 		
 		return ret;
 	}
+	
+	@Override
+	public List<StatementBlock> rewriteStatementBlocks(List<StatementBlock> sbs, 
+			ProgramRewriteStatus sate) throws HopsException {
+		return sbs;
+	}
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagDataDependentOperators.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagDataDependentOperators.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagDataDependentOperators.java
index 6c2fda9..351cf87 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagDataDependentOperators.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagDataDependentOperators.java
@@ -22,6 +22,7 @@ package org.apache.sysml.hops.rewrite;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.List;
 
 import org.apache.sysml.api.DMLScript;
 import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
@@ -70,7 +71,7 @@ public class RewriteSplitDagDataDependentOperators extends StatementBlockRewrite
 	private static IDSequence _seq = new IDSequence();
 	
 	@Override
-	public ArrayList<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus state)
+	public List<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus state)
 		throws HopsException 
 	{
 		//DAG splits not required for forced single node
@@ -184,21 +185,23 @@ public class RewriteSplitDagDataDependentOperators extends StatementBlockRewrite
 					sb1.liveOut().addVariable(varname, new DataIdentifier(diVar));
 					sb.liveIn().addVariable(varname, new DataIdentifier(diVar));
 				}
-		
+				
 				//ensure disjoint operators across DAGs (prevent replicated operations)
 				handleReplicatedOperators( sb1hops, sb.get_hops(), sb1.liveOut(), sb.liveIn() );
 				
 				//deep copy new dag (in order to prevent any dangling references)
 				sb1.set_hops(Recompiler.deepCopyHopsDag(sb1hops));
 				sb1.updateRecompilationFlag();
+				sb1.setSplitDag(true); //avoid later merge by other rewrites
 				
 				//recursive application of rewrite rule (in case of multiple data dependent operators
 				//with data dependencies in between each other)
-				ArrayList<StatementBlock> tmp = rewriteStatementBlock( sb1, state);
+				List<StatementBlock> tmp = rewriteStatementBlock(sb1, state);
 				
 				//add new statement blocks to output
 				ret.addAll(tmp); //statement block with data dependent hops
 				ret.add(sb); //statement block with remaining hops
+				sb.setSplitDag(true); //avoid later merge by other rewrites
 			}
 			catch(Exception ex)
 			{
@@ -466,4 +469,10 @@ public class RewriteSplitDagDataDependentOperators extends StatementBlockRewrite
 		
 		hop.setVisited();
 	}
+	
+	@Override
+	public List<StatementBlock> rewriteStatementBlocks(List<StatementBlock> sbs, 
+			ProgramRewriteStatus sate) throws HopsException {
+		return sbs;
+	}
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagUnknownCSVRead.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagUnknownCSVRead.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagUnknownCSVRead.java
index 2e9847a..6d9942f 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagUnknownCSVRead.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteSplitDagUnknownCSVRead.java
@@ -21,6 +21,7 @@ package org.apache.sysml.hops.rewrite;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 
 import org.apache.sysml.api.DMLScript;
 import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
@@ -44,14 +45,13 @@ import org.apache.sysml.runtime.controlprogram.caching.MatrixObject.UpdateType;
  */
 public class RewriteSplitDagUnknownCSVRead extends StatementBlockRewriteRule
 {
-
 	@Override
-	public ArrayList<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus state)
+	public List<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus state)
 		throws HopsException 
 	{
 		//DAG splits not required for forced single node
 		if( DMLScript.rtplatform == RUNTIME_PLATFORM.SINGLE_NODE )
-			return new ArrayList<StatementBlock>(Arrays.asList(sb));
+			return Arrays.asList(sb);
 		
 		ArrayList<StatementBlock> ret = new ArrayList<StatementBlock>();
 		
@@ -121,6 +121,7 @@ public class RewriteSplitDagUnknownCSVRead extends StatementBlockRewriteRule
 				sb1.updateRecompilationFlag();
 				ret.add(sb1); //statement block with csv reblocks
 				ret.add(sb); //statement block with remaining hops
+				sb.setSplitDag(true); //avoid later merge by other rewrites
 			}
 			catch(Exception ex)
 			{
@@ -137,8 +138,13 @@ public class RewriteSplitDagUnknownCSVRead extends StatementBlockRewriteRule
 		return ret;
 	}
 	
-	private void collectCSVReadHopsUnknownSize( ArrayList<Hop> roots, ArrayList<Hop> cand )
-	{
+	@Override
+	public List<StatementBlock> rewriteStatementBlocks(List<StatementBlock> sbs, 
+			ProgramRewriteStatus sate) throws HopsException {
+		return sbs;
+	}
+	
+	private void collectCSVReadHopsUnknownSize( ArrayList<Hop> roots, ArrayList<Hop> cand ) {
 		if( roots == null )
 			return;
 		

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/hops/rewrite/StatementBlockRewriteRule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/StatementBlockRewriteRule.java b/src/main/java/org/apache/sysml/hops/rewrite/StatementBlockRewriteRule.java
index 3d4b105..eba2276 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/StatementBlockRewriteRule.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/StatementBlockRewriteRule.java
@@ -19,7 +19,7 @@
 
 package org.apache.sysml.hops.rewrite;
 
-import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -34,19 +34,31 @@ import org.apache.sysml.parser.StatementBlock;
  */
 public abstract class StatementBlockRewriteRule 
 {
-
 	protected static final Log LOG = LogFactory.getLog(StatementBlockRewriteRule.class.getName());
-		
+	
 	/**
 	 * Handle an arbitrary statement block. Specific type constraints have to be ensured
-	 * within the individual rewrites.
+	 * within the individual rewrites. If a rewrite does not apply to individual blocks, it 
+	 * should simply return the input block.
 	 * 
 	 * @param sb statement block
 	 * @param sate program rewrite status
 	 * @return list of statement blocks
 	 * @throws HopsException if HopsException occurs
 	 */
-	public abstract ArrayList<StatementBlock> rewriteStatementBlock( StatementBlock sb, ProgramRewriteStatus sate ) 
+	public abstract List<StatementBlock> rewriteStatementBlock(StatementBlock sb, ProgramRewriteStatus sate) 
 		throws HopsException;
 	
+	/**
+	 * Handle a list of statement blocks. Specific type constraints have to be ensured
+	 * within the individual rewrites. If a rewrite does not require sequence access, it 
+	 * should simply return the input list of statement blocks.
+	 * 
+	 * @param sbs list of statement blocks
+	 * @param sate program rewrite status
+	 * @return list of statement blocks
+	 * @throws HopsException if HopsException occurs
+	 */
+	public abstract List<StatementBlock> rewriteStatementBlocks(List<StatementBlock> sbs, ProgramRewriteStatus sate) 
+		throws HopsException;
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/lops/compile/Dag.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/lops/compile/Dag.java b/src/main/java/org/apache/sysml/lops/compile/Dag.java
index 1da1ba6..8673fc9 100644
--- a/src/main/java/org/apache/sysml/lops/compile/Dag.java
+++ b/src/main/java/org/apache/sysml/lops/compile/Dag.java
@@ -3157,17 +3157,21 @@ public class Dag<N extends Lop>
 						MRJobLineNumbers.add(node._beginLine);
 					}
 					nodeIndexMapping.put(node, output_index);
-					return output_index;
 				}
 
 				return output_index;
 			}
-			else if (inputIndices.size() == 4) {
+			else if (inputIndices.size() == 4 || inputIndices.size() == 5) {
 				int output_index = start_index[0];
 				start_index[0]++;
-				otherInstructionsReducer.add(node.getInstructions(
-						inputIndices.get(0), inputIndices.get(1),
-						inputIndices.get(2), inputIndices.get(3), output_index));
+				if( inputIndices.size() == 4 )
+					otherInstructionsReducer.add(node.getInstructions(
+							inputIndices.get(0), inputIndices.get(1),
+							inputIndices.get(2), inputIndices.get(3), output_index));
+				else
+					otherInstructionsReducer.add(node.getInstructions(
+							inputIndices.get(0), inputIndices.get(1), inputIndices.get(2), 
+							inputIndices.get(3), inputIndices.get(4), output_index));
 				if(DMLScript.ENABLE_DEBUG_MODE) {
 					MRJobLineNumbers.add(node._beginLine);
 				}

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java b/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java
index 3ffc2d9..aa26f2d 100644
--- a/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java
+++ b/src/main/java/org/apache/sysml/parser/BuiltinFunctionExpression.java
@@ -1080,7 +1080,7 @@ public class BuiltinFunctionExpression extends DataIdentifier
 			//set output characteristics
 			output.setDataType(id.getDataType());
 			output.setDimensions(id.getDim1(), id2.getDim2());
-			output.setBlockDimensions(id.getRowsInBlock(), id.getColumnsInBlock()); 
+			output.setBlockDimensions(id.getRowsInBlock(), id.getColumnsInBlock());
 			break;
 		
 		case BIAS_ADD:

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/parser/DMLTranslator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/DMLTranslator.java b/src/main/java/org/apache/sysml/parser/DMLTranslator.java
index 818815d..731b300 100644
--- a/src/main/java/org/apache/sysml/parser/DMLTranslator.java
+++ b/src/main/java/org/apache/sysml/parser/DMLTranslator.java
@@ -1337,8 +1337,7 @@ public class DMLTranslator
 						Hop.OpOp1 op = Hop.OpOp1.PRINT;
 						Expression source = ps.getExpressions().get(0);
 						Hop ae = processExpression(source, target, ids);
-						Hop printHop = new UnaryOp(target.getName(), target.getDataType(), target.getValueType(), op,
-								ae);
+						Hop printHop = new UnaryOp(target.getName(), target.getDataType(), target.getValueType(), op, ae);
 						printHop.setAllPositions(current.getFilename(), current.getBeginLine(), current.getBeginColumn(), current.getEndLine(),
 								current.getEndColumn());
 						output.add(printHop);
@@ -1346,11 +1345,11 @@ public class DMLTranslator
 						Hop.OpOp1 op = Hop.OpOp1.STOP;
 						Expression source = ps.getExpressions().get(0);
 						Hop ae = processExpression(source, target, ids);
-						Hop stopHop = new UnaryOp(target.getName(), target.getDataType(), target.getValueType(), op,
-								ae);
+						Hop stopHop = new UnaryOp(target.getName(), target.getDataType(), target.getValueType(), op, ae);
 						stopHop.setAllPositions(current.getFilename(), current.getBeginLine(), current.getBeginColumn(), current.getEndLine(),
 								current.getEndColumn());
 						output.add(stopHop);
+						sb.setSplitDag(true); //avoid merge
 					} else if (ptype == PRINTTYPE.PRINTF) {
 						List<Expression> expressions = ps.getExpressions();
 						Hop[] inHops = new Hop[expressions.size()];

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/parser/LiveVariableAnalysis.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/LiveVariableAnalysis.java b/src/main/java/org/apache/sysml/parser/LiveVariableAnalysis.java
index 9133e33..cd13cb4 100644
--- a/src/main/java/org/apache/sysml/parser/LiveVariableAnalysis.java
+++ b/src/main/java/org/apache/sysml/parser/LiveVariableAnalysis.java
@@ -22,8 +22,6 @@ package org.apache.sysml.parser;
 
 public abstract class LiveVariableAnalysis 
 {
-
-		
 	VariableSet _read;
 	VariableSet _updated;
 	VariableSet _gen;
@@ -59,14 +57,26 @@ public abstract class LiveVariableAnalysis
 		return _kill;
 	}
 	
-	public void setLiveOut(VariableSet lo){
+	public VariableSet getGen(){
+		return _gen;
+	}
+	
+	public void setLiveOut(VariableSet lo) {
 		_liveOut = lo;
 	}
 	
-	public void setLiveIn(VariableSet li){
+	public void setLiveIn(VariableSet li) {
 		_liveIn = li;
 	}
 	
+	public void setKill(VariableSet ki) {
+		_kill = ki;
+	}
+	
+	public void setGen(VariableSet ge) {
+		_gen = ge;
+	}
+	
 	public void setUpdatedVariables( VariableSet vars ){
 		_updated = vars;
 	}

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/parser/StatementBlock.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/StatementBlock.java b/src/main/java/org/apache/sysml/parser/StatementBlock.java
index 79c7a9a..d5cf1d7 100644
--- a/src/main/java/org/apache/sysml/parser/StatementBlock.java
+++ b/src/main/java/org/apache/sysml/parser/StatementBlock.java
@@ -56,6 +56,7 @@ public class StatementBlock extends LiveVariableAnalysis
 
 	private ArrayList<String> _updateInPlaceVars = null;
 	private boolean _requiresRecompile = false;
+	private boolean _splitDag = false;
 
 	public StatementBlock() {
 		_dmlProg = null;
@@ -146,6 +147,14 @@ public class StatementBlock extends LiveVariableAnalysis
 		}
 		return true;
 	}
+	
+	public void setSplitDag(boolean flag) {
+		_splitDag = flag;
+	}
+	
+	public boolean isSplitDag() {
+		return _splitDag;
+	}
 
 
     public boolean isMergeableFunctionCallBlock(DMLProgram dmlProg) throws LanguageException{

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/parser/VariableSet.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/VariableSet.java b/src/main/java/org/apache/sysml/parser/VariableSet.java
index b1f5067..16ad08b 100644
--- a/src/main/java/org/apache/sysml/parser/VariableSet.java
+++ b/src/main/java/org/apache/sysml/parser/VariableSet.java
@@ -19,48 +19,37 @@
 
 package org.apache.sysml.parser;
 
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Set;
 
 public class VariableSet 
 {
-	
 	private HashMap<String,DataIdentifier> _variables;
 	
-	public VariableSet(){
+	public VariableSet() {
 		_variables = new HashMap<String,DataIdentifier>();
 	}
 	
-	public VariableSet( VariableSet vs )
-	{
+	public VariableSet( VariableSet vs ) {
 		_variables = new HashMap<String,DataIdentifier>();
-		
-		if (vs != null) {
-			HashMap<String,DataIdentifier> vars = vs.getVariables();
-			_variables.putAll(vars);
-		}		
+		if (vs != null)
+			_variables.putAll(vs.getVariables());
 	}
 	
-	public void addVariable(String name, DataIdentifier id)
-	{
+	public void addVariable(String name, DataIdentifier id) {
 		_variables.put(name,id);
 	}
 	
-	public void addVariables(VariableSet vs)
-	{
-		if (vs != null) {
-			HashMap<String,DataIdentifier> vars = vs.getVariables();
-			_variables.putAll(vars);
-		}
+	public void addVariables(VariableSet vs) {
+		if (vs != null)
+			_variables.putAll(vs.getVariables());
 	}
 	
-	public void removeVariables(VariableSet vs)
-	{
-		if( vs != null ){
-			Set<String> vars = vs.getVariables().keySet();
-			for (String var : vars)
+	public void removeVariables(VariableSet vs) {
+		if( vs != null )
+			for( String var : vs.getVariables().keySet() )
 				_variables.remove(var);
-		}
 	}
 
 	public boolean containsVariable(String name){
@@ -79,12 +68,20 @@ public class VariableSet
 		return _variables;
 	}
 	
-	public String toString(){
-		StringBuilder sb = new StringBuilder();
-		for (String var : _variables.keySet()){
-			sb.append(var + ",");
-		}
-		return sb.toString();
+	public String toString() {
+		return Arrays.toString(
+			_variables.keySet().toArray());
+	}
+	
+	public static VariableSet union(VariableSet vs1, VariableSet vs2) {
+		VariableSet ret = new VariableSet(vs1);
+		ret.addVariables(vs2);
+		return ret;
 	}
 	
+	public static VariableSet minus(VariableSet vs1, VariableSet vs2) {
+		VariableSet ret = new VariableSet(vs1);
+		ret.removeVariables(vs2);
+		return ret;
+	}
 }

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/main/java/org/apache/sysml/runtime/controlprogram/ParForProgramBlock.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/controlprogram/ParForProgramBlock.java b/src/main/java/org/apache/sysml/runtime/controlprogram/ParForProgramBlock.java
index 169c3bb..9f225c6 100644
--- a/src/main/java/org/apache/sysml/runtime/controlprogram/ParForProgramBlock.java
+++ b/src/main/java/org/apache/sysml/runtime/controlprogram/ParForProgramBlock.java
@@ -549,7 +549,7 @@ public class ParForProgramBlock extends ForProgramBlock
 	@Override	
 	public void execute(ExecutionContext ec)
 		throws DMLRuntimeException
-	{	
+	{
 		ParForStatementBlock sb = (ParForStatementBlock)getStatementBlock();
 		
 		// add the iterable predicate variable to the variable set

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/java/org/apache/sysml/test/integration/functions/misc/RewriteMergeBlocksTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/sysml/test/integration/functions/misc/RewriteMergeBlocksTest.java b/src/test/java/org/apache/sysml/test/integration/functions/misc/RewriteMergeBlocksTest.java
new file mode 100644
index 0000000..4a14ba6
--- /dev/null
+++ b/src/test/java/org/apache/sysml/test/integration/functions/misc/RewriteMergeBlocksTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sysml.test.integration.functions.misc;
+
+import java.util.HashMap;
+import org.junit.Test;
+import org.junit.Assert;
+import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex;
+import org.apache.sysml.test.integration.AutomatedTestBase;
+import org.apache.sysml.test.integration.TestConfiguration;
+import org.apache.sysml.test.utils.TestUtils;
+
+public class RewriteMergeBlocksTest extends AutomatedTestBase 
+{
+	private static final String TEST_NAME1 = "RewriteMergeIfCut"; //full merge
+	private static final String TEST_NAME2 = "RewriteMergeFunctionCut"; //only input merge
+
+	private static final String TEST_DIR = "functions/misc/";
+	private static final String TEST_CLASS_DIR = TEST_DIR + RewriteMergeBlocksTest.class.getSimpleName() + "/";
+	
+	private static final double eps = Math.pow(10,-10);
+	
+	@Override
+	public void setUp() {
+		TestUtils.clearAssertionInformation();
+		addTestConfiguration(TEST_NAME1, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[]{"R"}));
+		addTestConfiguration(TEST_NAME2, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME2, new String[]{"R"}));
+	}
+	
+	@Test
+	public void testIfCutMerge() {
+		testRewriteMerge(TEST_NAME1);
+	}
+	
+	@Test
+	public void testFunctionCutMerge() {
+		testRewriteMerge(TEST_NAME2);
+	}
+	
+	private void testRewriteMerge(String testname)
+	{	
+		TestConfiguration config = getTestConfiguration(testname);
+		loadTestConfiguration(config);
+		
+		String HOME = SCRIPT_DIR + TEST_DIR;
+		fullDMLScriptName = HOME + testname + ".dml";
+		programArgs = new String[]{ "-explain","-stats","-args", output("R") };
+		
+		fullRScriptName = HOME + testname + ".R";
+		rCmd = getRCmd(expectedDir());
+
+		runTest(true, false, null, -1); 
+		runRScript(true); 
+		
+		//compare outputs and check for compiled mmchain as proof for merge blocks 
+		HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("R");
+		HashMap<CellIndex, Double> rfile  = readRMatrixFromFS("R");
+		TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", "Stat-R");
+		Assert.assertTrue(testname.equals(TEST_NAME1) == 
+			heavyHittersContainsSubString("mmchain"));
+	}	
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java b/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java
index 88d1a28..b08f5b9 100644
--- a/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java
+++ b/src/test/java/org/apache/sysml/test/integration/mlcontext/MLContextTest.java
@@ -2652,7 +2652,7 @@ public class MLContextTest extends MLContextTestBase {
 	public void testFunctionNoReturnValueForceFunctionCallDML() {
 		System.out.println("MLContextTest - function with no return value, force function call DML");
 
-		String s = "hello=function(){\nif(1==1){};\nprint('no return value, force function call');\n}\nhello();";
+		String s = "hello=function(){\nwhile(FALSE){};\nprint('no return value, force function call');\n}\nhello();";
 		Script script = dml(s);
 		setExpectedStdOut("no return value, force function call");
 		ml.execute(script);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/applications/ctableStats/ctci.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/applications/ctableStats/ctci.dml b/src/test/scripts/applications/ctableStats/ctci.dml
index f545138..efed917 100644
--- a/src/test/scripts/applications/ctableStats/ctci.dml
+++ b/src/test/scripts/applications/ctableStats/ctci.dml
@@ -88,9 +88,9 @@ iBlock = 0;
 for (iLabel in 1:numLabels)
 {
     if (iLabel != nullLabel) {
-        if (1==1) {
-            print ("Processing label " + iLabel + ":");
-        }
+        print ("Processing label " + iLabel + ":");
+        while(FALSE){}
+        
         fCol = 1 + iBlock * 100;
         HeadMtx [iLabel, 1] = fCol + zero;
         cntPartitionsWithLabel = CT [, iLabel];

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/applications/ctableStats/ctci_odds.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/applications/ctableStats/ctci_odds.dml b/src/test/scripts/applications/ctableStats/ctci_odds.dml
index f13a25b..ba1b981 100644
--- a/src/test/scripts/applications/ctableStats/ctci_odds.dml
+++ b/src/test/scripts/applications/ctableStats/ctci_odds.dml
@@ -82,9 +82,8 @@ for (iLabel in 1:numLabels)
 {
     if (iLabel != nullLabel)
     {
-        if (1==1) {
-            print ("Processing label " + iLabel + ":");
-        }
+        print ("Processing label " + iLabel + ":");
+        
         for (iPartition in 1:numPartitions)
         {
             idx = idx + 1;

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/applications/id3/id3.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/applications/id3/id3.dml b/src/test/scripts/applications/id3/id3.dml
index 69b59e1..66a39f2 100644
--- a/src/test/scripts/applications/id3/id3.dml
+++ b/src/test/scripts/applications/id3/id3.dml
@@ -93,9 +93,9 @@
 id3_learn = function(Matrix[Double] X, Matrix[Double] y, Matrix[Double] X_subset, Matrix[Double] attributes, Double minsplit) return (Matrix[Double] nodes, Matrix[Double] edges){
 	hist_labels = aggregate(target=X_subset, groups=y, fn="sum")
 	
-	if (1==1) {
-	  print(" ");
-	}
+	print(" ");
+	while(FALSE){}
+	
 	#go through the histogram to compute the number of labels
 	#with non-zero samples
 	#and to pull out the most popular label
@@ -182,20 +182,17 @@ id3_learn = function(Matrix[Double] X, Matrix[Double] y, Matrix[Double] X_subset
 		
 		attr_vals = X[,best_attr]
 		attr_domain = aggregate(target=X_subset, groups=attr_vals, fn="sum")
-		if (1==1) {
-	  		print(" ");
-		}
+		print(" ");
+		while(FALSE){}
 
 		new_attributes = attributes
 		new_attributes[best_attr, 1] = 0
 		
 		max_sz_subtree = 2*sum(X_subset)
-		sz1 = 0
-		sz2 = 0
-		if(1==1){
-			sz2 = nrow(attr_domain)
-			sz1 = sz2*max_sz_subtree
-		}
+		sz2 = nrow(attr_domain)
+		sz1 = sz2*max_sz_subtree
+		while(FALSE){}
+		
 		tempNodeStore = matrix(0, rows=2, cols=sz1)
 		tempEdgeStore = matrix(0, rows=3, cols=sz1)
 		numSubtreeNodes = matrix(0, rows=sz2, cols=1)
@@ -225,17 +222,17 @@ id3_learn = function(Matrix[Double] X, Matrix[Double] y, Matrix[Double] X_subset
 		num_edges_in_subtrees = sum(numSubtreeEdges)
 		
 		#creating root node
-		if(1==1){
-			sz = 1+num_nodes_in_subtrees
-		}
+		sz = 1+num_nodes_in_subtrees
+		while(FALSE){}
+		
 		nodes = matrix(0, rows=sz, cols=2)
 		nodes[1,1] = best_attr
 		numNodes = 1
 		
 		#edges from root to children
-		if(1==1){
-			sz = sum(numSubtreeNodes > 0) + num_edges_in_subtrees
-		}
+		sz = sum(numSubtreeNodes > 0) + num_edges_in_subtrees
+		while(FALSE){}
+		
 		edges = matrix(1, rows=sz, cols=3)
 		numEdges = 0
 		for(i6 in 1:nrow(attr_domain)){

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/applications/mdabivar/MDABivariateStats.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/applications/mdabivar/MDABivariateStats.dml b/src/test/scripts/applications/mdabivar/MDABivariateStats.dml
index 1a47440..faf29b6 100644
--- a/src/test/scripts/applications/mdabivar/MDABivariateStats.dml
+++ b/src/test/scripts/applications/mdabivar/MDABivariateStats.dml
@@ -122,10 +122,9 @@ parfor(i3 in 1:nrow(feature_indices), check=0){
 			[pVal, contingencyTable, rowMarginals, colMarginals] = bivar_cc(labels, feature)
 			stats[feature_index2,1] = pVal
 			
-			sz3=1
-			if(1==1){
-				sz3 = nrow(contingencyTable)*ncol(contingencyTable)
-			}
+			sz3 = nrow(contingencyTable)*ncol(contingencyTable)
+			while(FALSE){}
+			
 			contingencyTableLabelValues = matrix(0, rows=1, cols=sz3)
 			contingencyTableFeatureValues = matrix(0, rows=1, cols=sz3)
 			

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/applications/validation/CV_LogisticRegression.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/applications/validation/CV_LogisticRegression.dml b/src/test/scripts/applications/validation/CV_LogisticRegression.dml
index 6e765e3..f072845 100644
--- a/src/test/scripts/applications/validation/CV_LogisticRegression.dml
+++ b/src/test/scripts/applications/validation/CV_LogisticRegression.dml
@@ -470,21 +470,7 @@ printFoldStatistics = function (Matrix[double] stats ) return( Integer err )
     stats_avg = round (colMeans(stats) * 10000.0) / 10000.0;
     stats_max = round (colMaxs (stats) * 10000.0) / 10000.0;
     stats_min = round (colMins (stats) * 10000.0) / 10000.0;
-/*    
-    print ("Training Data, Model-estimated statistics:");
-    print ("    True Positives:  Min = " + as.scalar (stats_min [1,  1]) + ",  Avg = " + as.scalar (stats_avg [1,  1]) + ",  Max = " + as.scalar (stats_max [1,  1]));
-    print ("   False Positives:  Min = " + as.scalar (stats_min [1,  2]) + ",  Avg = " + as.scalar (stats_avg [1,  2]) + ",  Max = " + as.scalar (stats_max [1,  2]));
-    print ("    True Negatives:  Min = " + as.scalar (stats_min [1,  3]) + ",  Avg = " + as.scalar (stats_avg [1,  3]) + ",  Max = " + as.scalar (stats_max [1,  3]));
-    print ("   False Negatives:  Min = " + as.scalar (stats_min [1,  4]) + ",  Avg = " + as.scalar (stats_avg [1,  4]) + ",  Max = " + as.scalar (stats_max [1,  4]));
-    print ("       Precision %:  Min = " + as.scalar (stats_min [1,  5]) + ",  Avg = " + as.scalar (stats_avg [1,  5]) + ",  Max = " + as.scalar (stats_max [1,  5]));
-    print ("Recall (Sensit-y)%:  Min = " + as.scalar (stats_min [1,  6]) + ",  Avg = " + as.scalar (stats_avg [1,  6]) + ",  Max = " + as.scalar (stats_max [1,  6]));
-    print ("     Specificity %:  Min = " + as.scalar (stats_min [1,  7]) + ",  Avg = " + as.scalar (stats_avg [1,  7]) + ",  Max = " + as.scalar (stats_max [1,  7]));
-    print ("      Value - Cost:  Min = " + as.scalar (stats_min [1,  8]) + ",  Avg = " + as.scalar (stats_avg [1,  8]) + ",  Max = " + as.scalar (stats_max [1,  8]));
-    print (" ");
-    if (1==1) {
-      print(" ")
-    }
-*/
+
     print ("Training Data, Label comparison statistics:");
     print ("    True Positives:  Min = " + as.scalar (stats_min [1, 11]) + ",  Avg = " + as.scalar (stats_avg [1, 11]) + ",  Max = " + as.scalar (stats_max [1, 11]));
     print ("   False Positives:  Min = " + as.scalar (stats_min [1, 12]) + ",  Avg = " + as.scalar (stats_avg [1, 12]) + ",  Max = " + as.scalar (stats_max [1, 12]));
@@ -495,24 +481,9 @@ printFoldStatistics = function (Matrix[double] stats ) return( Integer err )
     print ("     Specificity %:  Min = " + as.scalar (stats_min [1, 17]) + ",  Avg = " + as.scalar (stats_avg [1, 17]) + ",  Max = " + as.scalar (stats_max [1, 17]));
     print ("      Value - Cost:  Min = " + as.scalar (stats_min [1, 18]) + ",  Avg = " + as.scalar (stats_avg [1, 18]) + ",  Max = " + as.scalar (stats_max [1, 18]));
     print (" ");
-    if (1==1) {
-      print(" ")
-    }
-/*
-    print ("TEST Data, Model-estimated statistics:");
-    print ("    True Positives:  Min = " + as.scalar (stats_min [1, 21]) + ",  Avg = " + as.scalar (stats_avg [1, 21]) + ",  Max = " + as.scalar (stats_max [1, 21]));
-    print ("   False Positives:  Min = " + as.scalar (stats_min [1, 22]) + ",  Avg = " + as.scalar (stats_avg [1, 22]) + ",  Max = " + as.scalar (stats_max [1, 22]));
-    print ("    True Negatives:  Min = " + as.scalar (stats_min [1, 23]) + ",  Avg = " + as.scalar (stats_avg [1, 23]) + ",  Max = " + as.scalar (stats_max [1, 23]));
-    print ("   False Negatives:  Min = " + as.scalar (stats_min [1, 24]) + ",  Avg = " + as.scalar (stats_avg [1, 24]) + ",  Max = " + as.scalar (stats_max [1, 24]));
-    print ("       Precision %:  Min = " + as.scalar (stats_min [1, 25]) + ",  Avg = " + as.scalar (stats_avg [1, 25]) + ",  Max = " + as.scalar (stats_max [1, 25]));
-    print ("Recall (Sensit-y)%:  Min = " + as.scalar (stats_min [1, 26]) + ",  Avg = " + as.scalar (stats_avg [1, 26]) + ",  Max = " + as.scalar (stats_max [1, 26]));
-    print ("     Specificity %:  Min = " + as.scalar (stats_min [1, 27]) + ",  Avg = " + as.scalar (stats_avg [1, 27]) + ",  Max = " + as.scalar (stats_max [1, 27]));
-    print ("      Value - Cost:  Min = " + as.scalar (stats_min [1, 28]) + ",  Avg = " + as.scalar (stats_avg [1, 28]) + ",  Max = " + as.scalar (stats_max [1, 28]));
-    print (" ");
-    if (1==1) {
-      print(" ")
-    }
-*/
+    print(" ")
+    while(FALSE){}
+
     print ("TEST Data, Label comparison statistics:");
     print ("    True Positives:  Min = " + as.scalar (stats_min [1, 31]) + ",  Avg = " + as.scalar (stats_avg [1, 31]) + ",  Max = " + as.scalar (stats_max [1, 31]));
     print ("   False Positives:  Min = " + as.scalar (stats_min [1, 32]) + ",  Avg = " + as.scalar (stats_avg [1, 32]) + ",  Max = " + as.scalar (stats_max [1, 32]));

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/applications/validation/CV_MultiClassSVM.sasha.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/applications/validation/CV_MultiClassSVM.sasha.dml b/src/test/scripts/applications/validation/CV_MultiClassSVM.sasha.dml
index 0943f1a..c0326ff 100644
--- a/src/test/scripts/applications/validation/CV_MultiClassSVM.sasha.dml
+++ b/src/test/scripts/applications/validation/CV_MultiClassSVM.sasha.dml
@@ -314,9 +314,9 @@ printFoldStatistics = function (Matrix[double] stats ) return( Integer err )
     print ("     Precision %:  Min = " + as.scalar (stats_min [1, 15]) + ",  Avg = " + as.scalar (stats_avg [1, 15]) + ",  Max = " + as.scalar (stats_max [1, 15]));
 
     print (" ");
-    if (1==1) {
-      print(" ")
-    }
+    print(" ")
+    while(FALSE){}
+    
     print ("TEST Data, Label comparison statistics:");
     print ("    True Matches:  Min = " + as.scalar (stats_min [1, 31]) + ",  Avg = " + as.scalar (stats_avg [1, 31]) + ",  Max = " + as.scalar (stats_max [1, 31]));
     print ("   False Matches:  Min = " + as.scalar (stats_min [1, 32]) + ",  Avg = " + as.scalar (stats_avg [1, 32]) + ",  Max = " + as.scalar (stats_max [1, 32]));

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/SumAdditionChain.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/SumAdditionChain.dml b/src/test/scripts/functions/codegen/SumAdditionChain.dml
index 87b0143..db4acf6 100644
--- a/src/test/scripts/functions/codegen/SumAdditionChain.dml
+++ b/src/test/scripts/functions/codegen/SumAdditionChain.dml
@@ -23,7 +23,7 @@ X = read($1)
 Y = X + 2;
 Z = X + 3;
 
-if(1==1){}
+while(FALSE){}
 
 R = as.matrix(sum(X+Y+Z));
 write(R, $2)

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/SumProductChain.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/SumProductChain.dml b/src/test/scripts/functions/codegen/SumProductChain.dml
index 2b65ee1..b899689 100644
--- a/src/test/scripts/functions/codegen/SumProductChain.dml
+++ b/src/test/scripts/functions/codegen/SumProductChain.dml
@@ -23,7 +23,7 @@ X = read($1)
 Y = X + 2;
 Z = X + 3;
 
-if(1==1){}
+while(FALSE){}
 
 R = as.matrix(sum(X*Y*Z));
 write(R, $2)

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/cellwisetmpl15.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl15.dml b/src/test/scripts/functions/codegen/cellwisetmpl15.dml
index e543671..5f95196 100644
--- a/src/test/scripts/functions/codegen/cellwisetmpl15.dml
+++ b/src/test/scripts/functions/codegen/cellwisetmpl15.dml
@@ -20,7 +20,7 @@
 #-------------------------------------------------------------
 
 X = matrix(seq(7, 1100*200+6), 1100, 200);
-if(1==1){}
+while(FALSE){}
 
 R = colMins(2*log(X));
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/cellwisetmpl16.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl16.dml b/src/test/scripts/functions/codegen/cellwisetmpl16.dml
index 1fb07b5..c3da55f 100644
--- a/src/test/scripts/functions/codegen/cellwisetmpl16.dml
+++ b/src/test/scripts/functions/codegen/cellwisetmpl16.dml
@@ -20,7 +20,7 @@
 #-------------------------------------------------------------
 
 X = matrix(seq(7, 1100*200+6), 1100, 200);
-if(1==1){}
+while(FALSE){}
 
 R = colSums(2*log(X));
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/cellwisetmpl7.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl7.dml b/src/test/scripts/functions/codegen/cellwisetmpl7.dml
index 6b2afd3..6124969 100644
--- a/src/test/scripts/functions/codegen/cellwisetmpl7.dml
+++ b/src/test/scripts/functions/codegen/cellwisetmpl7.dml
@@ -24,7 +24,7 @@ Y = seq(6, 1006);
 
 Z = X + Y - 7 + abs(X);
 R = as.scalar(t(Z) %*% Z)
-if(1==1){}
+while(FALSE){}
 
 print(R)
 write(R, $1)

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/cellwisetmpl8.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl8.R b/src/test/scripts/functions/codegen/cellwisetmpl8.R
index 9ad506b..20ea454 100644
--- a/src/test/scripts/functions/codegen/cellwisetmpl8.R
+++ b/src/test/scripts/functions/codegen/cellwisetmpl8.R
@@ -26,7 +26,6 @@ library("Matrix")
 X = matrix(1, 1002, 23);
 Y = seq(1, 1002);
 X[100:900,] = matrix(0, 801, 23); 
-if(1==1){}
 
 R = X * ((X + 7.7) * (Y%*%matrix(1,1,23)));
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/cellwisetmpl8.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/cellwisetmpl8.dml b/src/test/scripts/functions/codegen/cellwisetmpl8.dml
index d330d70..9fe6b5d 100644
--- a/src/test/scripts/functions/codegen/cellwisetmpl8.dml
+++ b/src/test/scripts/functions/codegen/cellwisetmpl8.dml
@@ -22,7 +22,7 @@
 X = matrix(1, rows=1002, cols=23);
 Y = seq(1, 1002);
 X[100:900,] = matrix(0, rows=801, cols=23); 
-if(1==1){}
+while(FALSE){}
 
 R = X * ((X + 7.7) * Y);
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/miscPattern1.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/miscPattern1.dml b/src/test/scripts/functions/codegen/miscPattern1.dml
index 6c8dbd9..528e8eb 100644
--- a/src/test/scripts/functions/codegen/miscPattern1.dml
+++ b/src/test/scripts/functions/codegen/miscPattern1.dml
@@ -25,11 +25,11 @@ U = matrix(3, 1100, 10);
 V = matrix(4, 2200, 10)
 X[4:900,3:1000] = matrix(0, 897, 998);
 
-if(1==1){}
+while(FALSE){}
 
 R1 = Y + (X * U%*%t(V));
 
-if(1==1){}
+while(FALSE){}
 
 R2 = as.matrix(sum(R1));
 write(R2, $1)

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/miscPattern2.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/miscPattern2.dml b/src/test/scripts/functions/codegen/miscPattern2.dml
index 8c2a35b..d6a5c6c 100644
--- a/src/test/scripts/functions/codegen/miscPattern2.dml
+++ b/src/test/scripts/functions/codegen/miscPattern2.dml
@@ -22,7 +22,7 @@
 X = matrix(1, 2340, 7);
 Y = matrix(2, 2340, 7);
 
-if(1==1){}
+while(FALSE){}
 
 Z = abs(exp((log(exp(X + Y))+7)/7));
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/multiAggPattern7.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/multiAggPattern7.dml b/src/test/scripts/functions/codegen/multiAggPattern7.dml
index 3306fd8..e727533 100644
--- a/src/test/scripts/functions/codegen/multiAggPattern7.dml
+++ b/src/test/scripts/functions/codegen/multiAggPattern7.dml
@@ -21,7 +21,7 @@
 
 X = seq(1,15);
 Y = seq(2,16);
-if(1==1){}
+while(FALSE){}
 
 r1 = t(X)%*%X;
 r2 = t(X)%*%Y;

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/rowAggPattern17.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern17.dml b/src/test/scripts/functions/codegen/rowAggPattern17.dml
index 1a7ce93..b8d026b 100644
--- a/src/test/scripts/functions/codegen/rowAggPattern17.dml
+++ b/src/test/scripts/functions/codegen/rowAggPattern17.dml
@@ -23,10 +23,10 @@ X = matrix(seq(1,1500), 150, 10);
 P = matrix(2, nrow(X), 2);
 Y0 = matrix(1, nrow(X), 1);
 max_y = max(Y0)+1;
-if(1==1){}
+while(FALSE){}
 Y = table(seq(1,nrow(Y0)), Y0, nrow(Y0), max_y);
 
-if(1==1){} #recompile w/o knowing K
+while(FALSE){} #recompile w/o knowing K
 K = ncol(Y)-1;
 R = t(X) %*% (P [, 1:K] - Y [, 1:K]);
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/rowAggPattern19.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern19.dml b/src/test/scripts/functions/codegen/rowAggPattern19.dml
index cb1fa3d..b78c5c4 100644
--- a/src/test/scripts/functions/codegen/rowAggPattern19.dml
+++ b/src/test/scripts/functions/codegen/rowAggPattern19.dml
@@ -21,7 +21,7 @@
 
 LT = matrix(1, 1500, 2);
 Y = matrix(2, 1500, 2);
-if(1==1) {}
+while(FALSE){}
   
 LT = LT - rowMaxs (LT);
 exp_LT = exp (LT);

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/rowAggPattern23.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern23.dml b/src/test/scripts/functions/codegen/rowAggPattern23.dml
index 4aafd0f..ba6606f 100644
--- a/src/test/scripts/functions/codegen/rowAggPattern23.dml
+++ b/src/test/scripts/functions/codegen/rowAggPattern23.dml
@@ -23,7 +23,7 @@
 X = matrix(seq(1,3000), 60, 50);
 Y = seq(1,60);
 Xw = seq(2,61);
-if(1==1){}
+while(FALSE){}
 
 out = 1 - Y * Xw
 sv = (out > 0)
@@ -31,7 +31,7 @@ out = sv * out
 obj = 0.5 * sum(out * out)
 g_new = t(X) %*% (out * Y)
 
-if(1==1){}
+while(FALSE){}
 R = as.matrix(obj + sum(g_new));
 
 write(R, $1)

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/rowAggPattern24.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern24.dml b/src/test/scripts/functions/codegen/rowAggPattern24.dml
index 200d552..70ac431 100644
--- a/src/test/scripts/functions/codegen/rowAggPattern24.dml
+++ b/src/test/scripts/functions/codegen/rowAggPattern24.dml
@@ -23,7 +23,7 @@
 X = matrix(seq(1,6000)/6000, 600, 10);
 w = matrix(seq(1,2400)/2400, 600, 4);
 v = matrix(seq(1,40)/40, 10, 4);
-if(1==1){}
+while(FALSE){}
 
 R = t(X) %*% (w * (X %*% v));
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/rowAggPattern25.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern25.dml b/src/test/scripts/functions/codegen/rowAggPattern25.dml
index fa8775e..de601a4 100644
--- a/src/test/scripts/functions/codegen/rowAggPattern25.dml
+++ b/src/test/scripts/functions/codegen/rowAggPattern25.dml
@@ -22,7 +22,7 @@
 
 X = matrix(seq(1,6000), 600, 10);
 C = matrix(seq(1,40), 4, 10);
-if(1==1){}
+while(FALSE){}
 
 R = -2 * (X %*% t(C)) + t(rowSums(C^2))
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/rowAggPattern26.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern26.dml b/src/test/scripts/functions/codegen/rowAggPattern26.dml
index f84b556..2c40e26 100644
--- a/src/test/scripts/functions/codegen/rowAggPattern26.dml
+++ b/src/test/scripts/functions/codegen/rowAggPattern26.dml
@@ -21,7 +21,7 @@
 
 X = matrix(seq(1,6000), 600, 10);
 P = matrix(seq(1,3000), 600, 5)
-if(1==1){}
+while(FALSE){}
 
 R = t(P) %*% X;
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/rowAggPattern27.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern27.dml b/src/test/scripts/functions/codegen/rowAggPattern27.dml
index c5254c2..825f83b 100644
--- a/src/test/scripts/functions/codegen/rowAggPattern27.dml
+++ b/src/test/scripts/functions/codegen/rowAggPattern27.dml
@@ -22,7 +22,7 @@
 
 X = matrix(seq(1,6000)/6000, 600, 10);
 v = matrix(seq(1,40)/40, 10, 4);
-if(1==1){}
+while(FALSE){}
 
 R = t(X) %*% (X %*% v);
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/rowAggPattern28.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern28.dml b/src/test/scripts/functions/codegen/rowAggPattern28.dml
index bc40685..f7a6df5 100644
--- a/src/test/scripts/functions/codegen/rowAggPattern28.dml
+++ b/src/test/scripts/functions/codegen/rowAggPattern28.dml
@@ -22,7 +22,7 @@
 
 X = matrix(seq(1,6000)/6000, 600, 10);
 C = matrix(seq(1,40)/40, 4, 10);
-if(1==1){}
+while(FALSE){}
 
 D =  -2 * (X %*% t(C)) + t(rowSums (C ^ 2));
 P = (D <= rowMins (D));

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/rowAggPattern29.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern29.dml b/src/test/scripts/functions/codegen/rowAggPattern29.dml
index 236d449..1081b50 100644
--- a/src/test/scripts/functions/codegen/rowAggPattern29.dml
+++ b/src/test/scripts/functions/codegen/rowAggPattern29.dml
@@ -21,7 +21,7 @@
 
 
 X = matrix(seq(1,6000)/6000, 600, 10);
-if(1==1){}
+while(FALSE){}
 
 R = as.matrix(sum(rowMins(X)));
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/rowAggPattern30.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/rowAggPattern30.dml b/src/test/scripts/functions/codegen/rowAggPattern30.dml
index 60e5e54..7df215d 100644
--- a/src/test/scripts/functions/codegen/rowAggPattern30.dml
+++ b/src/test/scripts/functions/codegen/rowAggPattern30.dml
@@ -25,7 +25,7 @@ ssX_V = matrix(seq(1,40), 10, 4)/40;
 P = matrix(seq(1,3000), 600, 5)/3000;
 K = 4;
 
-if(1==1){}
+while(FALSE){}
 Q = P[,1:K] * (X %*% ssX_V);
 R = t(X) %*% (Q - P[,1:K] * rowSums(Q));
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/wSparseUnsafeOuterProduct.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wSparseUnsafeOuterProduct.dml b/src/test/scripts/functions/codegen/wSparseUnsafeOuterProduct.dml
index 61748f6..d209591 100644
--- a/src/test/scripts/functions/codegen/wSparseUnsafeOuterProduct.dml
+++ b/src/test/scripts/functions/codegen/wSparseUnsafeOuterProduct.dml
@@ -24,7 +24,7 @@ X[100:900,] = matrix(0, rows=801, cols=2000)
 U = matrix( 4, rows=1000, cols=10)
 V = matrix( 5, rows=2000, cols=10)
 
-if(1==1){}
+while(FALSE){}
 
 S = X+1/(U%*%t(V));
 write(S,$1)

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/wcemm.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wcemm.dml b/src/test/scripts/functions/codegen/wcemm.dml
index 32ff880..c83bc04 100644
--- a/src/test/scripts/functions/codegen/wcemm.dml
+++ b/src/test/scripts/functions/codegen/wcemm.dml
@@ -22,7 +22,7 @@
 X= read($2)
 U= matrix( 1, rows=2000, cols=10)
 V= matrix( 2, rows=2000, cols=10)
-if(1==1){}
+while(FALSE){}
 
 eps = 0.1
 S= sum(X*log(U%*%t(V)+eps))

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/wdivmm.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wdivmm.dml b/src/test/scripts/functions/codegen/wdivmm.dml
index 0a3d324..083bb19 100644
--- a/src/test/scripts/functions/codegen/wdivmm.dml
+++ b/src/test/scripts/functions/codegen/wdivmm.dml
@@ -22,7 +22,7 @@
 X = matrix( 3, rows=4000, cols=2000)
 U = matrix( 4, rows=4000, cols=10)
 V = matrix( 5, rows=2000, cols=10)
-if(1==1){}
+while(FALSE){}
 eps = 0.1
 S= t(t(U) %*% (X/(U%*%t(V)+eps)))
 

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/wdivmmRight.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wdivmmRight.dml b/src/test/scripts/functions/codegen/wdivmmRight.dml
index 97a5baf..6c6549d 100644
--- a/src/test/scripts/functions/codegen/wdivmmRight.dml
+++ b/src/test/scripts/functions/codegen/wdivmmRight.dml
@@ -23,7 +23,7 @@ X = matrix( 3, rows=4000, cols=2000)
 U = matrix( 4, rows=4000, cols=10)
 V = matrix( 5, rows=2000, cols=10)
 
-if(1==1){}
+while(FALSE){}
 
 eps = 0.1
 S= (X/(U%*%t(V)))%*%V

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/wdivmmRightNotranspose.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wdivmmRightNotranspose.dml b/src/test/scripts/functions/codegen/wdivmmRightNotranspose.dml
index 730e526..6138684 100644
--- a/src/test/scripts/functions/codegen/wdivmmRightNotranspose.dml
+++ b/src/test/scripts/functions/codegen/wdivmmRightNotranspose.dml
@@ -23,7 +23,7 @@ X = matrix( 3, rows=4000, cols=2000)
 U = matrix( 4, rows=4000, cols=10)
 V = matrix( 5, rows=10, cols=2000)
 
-if(1==1){}
+while(FALSE){}
 
 eps = 0.1
 S= (X/((U%*%V)+eps))%*%t(V)

http://git-wip-us.apache.org/repos/asf/systemml/blob/4b81d0dd/src/test/scripts/functions/codegen/wdivmmTransposeOut.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/codegen/wdivmmTransposeOut.dml b/src/test/scripts/functions/codegen/wdivmmTransposeOut.dml
index 2e1f40f..570116e 100644
--- a/src/test/scripts/functions/codegen/wdivmmTransposeOut.dml
+++ b/src/test/scripts/functions/codegen/wdivmmTransposeOut.dml
@@ -23,7 +23,7 @@ X = matrix( 3, rows=4000, cols=2000)
 U = matrix( 4, rows=4000, cols=10)
 V = matrix( 5, rows=10, cols=2000)
 
-if(1==1){}
+while(FALSE){}
 
 eps = 0.1
 S= (t(U) %*% (X/((U%*%V)+eps)))