Fix constant propagation alg. in for statement like Mario suggestion.
authorManuele Conti <conti.ma@alice.it>
Fri, 28 Dec 2012 16:24:17 +0100
changeset 782 c8cd69801b7e
parent 781 577547327f67
child 783 3bd2704d9ba9
Fix constant propagation alg. in for statement like Mario suggestion.
stage3/constant_folding.cc
--- a/stage3/constant_folding.cc	Fri Dec 28 11:22:02 2012 +0100
+++ b/stage3/constant_folding.cc	Fri Dec 28 16:24:17 2012 +0100
@@ -1315,8 +1315,19 @@
 	std::map <std::string, symbol_c::const_value_t> values_incoming;
 	std::map <std::string, symbol_c::const_value_t> values_statement_result;
 	std::map <std::string, symbol_c::const_value_t>::iterator itr;
+	std::string varName;
 
 	values_incoming = values; /* save incoming status */
+	symbol->beg_expression->accept(*this);
+	symbol->end_expression->accept(*this);
+	varName = convert.toString(symbol->control_variable);
+	values[varName] = symbol->beg_expression->const_value;
+
+	/* Optimize dead code */
+	if (VALID_CVALUE(int64, symbol->beg_expression) && VALID_CVALUE(int64, symbol->end_expression) &&
+		  GET_CVALUE(int64, symbol->beg_expression) >    GET_CVALUE(int64, symbol->end_expression))
+		return NULL;
+
 	symbol->statement_list->accept(*this);
 	values_statement_result = values;
 	values.clear();