Only set MEM2REG_FL_CONST_LHS/MEM2REG_FL_VAR_LHS for non-init writes, fixes #867
authorClifford Wolf <clifford@clifford.at>
Tue, 12 Mar 2019 19:09:47 +0000 (20:09 +0100)
committerClifford Wolf <clifford@clifford.at>
Tue, 12 Mar 2019 19:09:47 +0000 (20:09 +0100)
Signed-off-by: Clifford Wolf <clifford@clifford.at>
frontends/ast/simplify.cc

index ae7dec88d9b506de2d6df3f62272bf41eaa8145f..f747a07cd1732e8b661dd9e4763e44efefed1c1b 100644 (file)
@@ -2954,12 +2954,14 @@ void AstNode::mem2reg_as_needed_pass1(dict<AstNode*, pool<std::string>> &mem2reg
                                proc_flags[mem] |= AstNode::MEM2REG_FL_EQ1;
                        }
 
-                       // remember if this is a constant index or not
-                       if (children[0]->children.size() && children[0]->children[0]->type == AST_RANGE && children[0]->children[0]->children.size()) {
-                               if (children[0]->children[0]->children[0]->type == AST_CONSTANT)
-                                       mem2reg_candidates[mem] |= AstNode::MEM2REG_FL_CONST_LHS;
-                               else
-                                       mem2reg_candidates[mem] |= AstNode::MEM2REG_FL_VAR_LHS;
+                       // for proper (non-init) writes: remember if this is a constant index or not
+                       if ((flags & MEM2REG_FL_INIT) == 0) {
+                               if (children[0]->children.size() && children[0]->children[0]->type == AST_RANGE && children[0]->children[0]->children.size()) {
+                                       if (children[0]->children[0]->children[0]->type == AST_CONSTANT)
+                                               mem2reg_candidates[mem] |= AstNode::MEM2REG_FL_CONST_LHS;
+                                       else
+                                               mem2reg_candidates[mem] |= AstNode::MEM2REG_FL_VAR_LHS;
+                               }
                        }
 
                        // remember where this is