|
| 1 | +# Examples from #3426 |
| 2 | + |
| 3 | +read_verilog <<EOT |
| 4 | +module top( |
| 5 | + input wire in, |
| 6 | + output wire out1, out2 |
| 7 | +); |
| 8 | + |
| 9 | +wire int1, int2; |
| 10 | +assign int1 = in; |
| 11 | +assign out1 = in; |
| 12 | +assign out2 = int2; |
| 13 | + |
| 14 | +endmodule |
| 15 | +EOT |
| 16 | + |
| 17 | +optbarriers |
| 18 | +select -assert-any t:$barrier |
| 19 | + |
| 20 | +opt_clean |
| 21 | + |
| 22 | +# Check connections through barriers, e.g. out2 has int2 as input |
| 23 | +select -assert-count 0 w:out2 %ci2 w:int1 %i |
| 24 | +select -assert-count 1 w:out2 %ci2 w:int2 %i |
| 25 | +select -assert-count 0 w:out2 %ci2 w:in %i |
| 26 | +select -assert-count 0 w:out2 %ci2 w:out1 %i |
| 27 | + |
| 28 | +select -assert-count 0 w:out1 %ci2 w:int1 %i |
| 29 | +select -assert-count 0 w:out1 %ci2 w:int2 %i |
| 30 | +select -assert-count 1 w:out1 %ci2 w:in %i |
| 31 | +select -assert-count 0 w:out1 %ci2 w:out2 %i |
| 32 | + |
| 33 | +select -assert-count 0 w:int1 %ci2 w:int2 %i |
| 34 | +select -assert-count 0 w:int1 %ci2 w:in %i |
| 35 | +select -assert-count 0 w:int1 %ci2 w:out1 %i |
| 36 | +select -assert-count 0 w:int1 %ci2 w:out2 %i |
| 37 | + |
| 38 | +select -assert-count 0 w:int2 %ci2 w:int1 %i |
| 39 | +select -assert-count 0 w:int2 %ci2 w:in %i |
| 40 | +select -assert-count 0 w:int2 %ci2 w:out1 %i |
| 41 | +select -assert-count 0 w:int2 %ci2 w:out2 %i |
| 42 | + |
| 43 | +select -assert-count 0 w:in %ci2 w:int1 %i |
| 44 | +select -assert-count 0 w:in %ci2 w:int2 %i |
| 45 | +select -assert-count 0 w:in %ci2 w:out1 %i |
| 46 | +select -assert-count 0 w:in %ci2 w:out2 %i |
| 47 | + |
| 48 | +design -reset |
| 49 | + |
| 50 | +read_verilog <<EOT |
| 51 | +module top( |
| 52 | + input wire in, |
| 53 | + output wire out1, out2, out3 |
| 54 | +); |
| 55 | + |
| 56 | +wire int1, int2; |
| 57 | +assign int1 = in; |
| 58 | +assign int2 = int1; |
| 59 | + |
| 60 | +assign out1 = int1; |
| 61 | +assign out2 = int2; |
| 62 | +assign out3 = out1 | out2; |
| 63 | + |
| 64 | +endmodule |
| 65 | +EOT |
| 66 | + |
| 67 | +optbarriers |
| 68 | +opt_clean |
| 69 | + |
| 70 | +# Ensure int1 is still in fanin of int2/out1/out2/out3 |
| 71 | +select -assert-count 1 w:int2 %ci* w:int1 %i |
| 72 | +select -assert-count 1 w:out1 %ci* w:int1 %i |
| 73 | +select -assert-count 1 w:out2 %ci* w:int1 %i |
| 74 | +select -assert-count 1 w:out3 %ci* w:int1 %i |
| 75 | + |
| 76 | +design -reset |
| 77 | + |
| 78 | +# Some basic tests that adding and removing barriers is a no-op functionally and |
| 79 | +# prevents optimizations |
| 80 | + |
| 81 | +read_verilog <<EOT |
| 82 | +module top( |
| 83 | + output wire [7:0] d |
| 84 | +); |
| 85 | + |
| 86 | +wire [7:0] a, b, c; |
| 87 | + |
| 88 | +assign d = a + b + c; |
| 89 | + |
| 90 | +assign a = 12; |
| 91 | +assign b = 13; |
| 92 | +assign c = 61; |
| 93 | + |
| 94 | +endmodule |
| 95 | +EOT |
| 96 | + |
| 97 | +# Without barriers additions are const folded |
| 98 | +design -push-copy |
| 99 | +prep |
| 100 | +select -assert-none t:$add |
| 101 | +design -pop |
| 102 | + |
| 103 | +# With barriers they aren't |
| 104 | +prep -barriers |
| 105 | +select -assert-count 2 t:$add |
| 106 | + |
| 107 | +design -reset |
| 108 | + |
| 109 | +# Processes including self-assignment |
| 110 | + |
| 111 | +read_verilog <<EOT |
| 112 | +module top( |
| 113 | + input wire clk, |
| 114 | + input wire rst, |
| 115 | + input wire [7:0] a, |
| 116 | + input wire [7:0] b, |
| 117 | + output wire [7:0] c, |
| 118 | + output wire [7:0] d |
| 119 | +); |
| 120 | + |
| 121 | +always @(posedge clk) begin |
| 122 | + if (rst) begin |
| 123 | + c <= '0; |
| 124 | + d <= b; |
| 125 | + end else begin |
| 126 | + c <= a; |
| 127 | + end |
| 128 | +end |
| 129 | + |
| 130 | +endmodule |
| 131 | +EOT |
| 132 | + |
| 133 | +copy top top_gold |
| 134 | +optbarriers top |
| 135 | +proc |
| 136 | +select -assert-any t:$barrier |
| 137 | +optbarriers -remove |
| 138 | +select -assert-none t:$barrier |
| 139 | + |
| 140 | +equiv_make top top_gold equiv |
| 141 | +equiv_induct equiv |
| 142 | +equiv_status -assert |
| 143 | + |
| 144 | +design -reset |
| 145 | + |
| 146 | +read_verilog <<EOT |
| 147 | +module top( |
| 148 | + input wire [7:0] a, |
| 149 | + input wire [7:0] b, |
| 150 | + output wire [7:0] c, |
| 151 | + output wire [7:0] d |
| 152 | +); |
| 153 | + |
| 154 | +assign c = a + b; |
| 155 | +assign d = a + b; |
| 156 | + |
| 157 | +endmodule |
| 158 | +EOT |
| 159 | + |
| 160 | +# Without barriers c and d are merged |
| 161 | +design -push-copy |
| 162 | +prep |
| 163 | +select -assert-any w:c %ci1 w:d %ci1 %i |
| 164 | +design -pop |
| 165 | + |
| 166 | +# With barriers they aren't |
| 167 | +prep -barriers |
| 168 | +select -assert-none w:c %ci1 w:d %ci1 %i |
0 commit comments