Allow constant function calls in constant function arguments
authorZachary Snow <zach@zachjs.com>
Mon, 7 Dec 2020 20:52:44 +0000 (13:52 -0700)
committerZachary Snow <zach@zachjs.com>
Mon, 7 Dec 2020 20:53:27 +0000 (13:53 -0700)
frontends/ast/simplify.cc
tests/various/const_arg_loop.v

index fb6623f023844c4407b65cbe7ecd56a123255177..8e205cb76828c4905bda4a1cf134ff4e10073449 100644 (file)
@@ -1205,6 +1205,11 @@ bool AstNode::simplify(bool const_fold, bool at_zero, bool in_lvalue, int stage,
                                current_block = this;
                                current_block_child = children[i];
                        }
+                       if (!in_param_here && type == AST_FCALL) {
+                               bool recommend_const_eval = false;
+                               bool require_const_eval = has_const_only_constructs(recommend_const_eval);
+                               in_param_here = recommend_const_eval || require_const_eval;
+                       }
                        if ((type == AST_ALWAYS || type == AST_INITIAL) && children[i]->type == AST_BLOCK)
                                current_top_block = children[i];
                        if (i == 0 && child_0_is_self_determined)
index 3bfff4acd8dadb1e4e5dd25a0f930987647e459e..76cc67abb7861c00b718c656a599a1ff2fb46eef 100644 (file)
@@ -14,6 +14,11 @@ module top;
                end
        endfunction
 
+       function automatic [31:0] pass_through;
+               input [31:0] inp;
+               pass_through = inp;
+       endfunction
+
        function automatic [31:0] operation2;
                input [4:0] var;
                input integer num;
@@ -47,6 +52,9 @@ module top;
        wire [31:0] x1;
        assign x1 = operation1(A, a);
 
+       wire [31:0] x1b;
+       assign x1b = operation1(pass_through(A), a);
+
        wire [31:0] x2;
        assign x2 = operation2(A, a);
 
@@ -58,6 +66,7 @@ module top;
     assert property (a == 2);
     assert property (A == 3);
     assert property (x1 == 16);
+    assert property (x1b == 16);
     assert property (x2 == 4);
     assert property (x3 == 16);
 `endif