When optimizing the size of a case keep the sign of the condition

This commit is contained in:
Cary R 2025-06-25 00:10:31 -07:00
parent 6426afc8d0
commit 46a5078a68
4 changed files with 35 additions and 2 deletions

View File

@ -0,0 +1,30 @@
// The ternary operator should cause the 'in' variable to be unsigned extended.
module test;
reg passed;
reg [7:0] res;
reg signed in;
initial begin
passed = 1'b1;
in = 1;
$display("in4: %0d", in);
res = 0 ? 1'h0 : in;
$display("T0 = %d, %d", 0 ? 1'h0 : in, res); // These work
case (0 ? 1'h0 : in) // But this fails
5'b0101: begin $display("FAILED: T0 matched 5'b0101"); passed = 1'b0;end
8'b000001: begin $display("T0 matched 8'b000001"); end
default: begin $display("FAILED: T0 matched default"); passed = 1'b0;end
endcase
res = 1 ? in : 1'h0;
$display("T1 = %d, %d", 1 ? in : 1'h0, res); // These work
case (1 ? in : 1'h0) // But this fails
5'b0101: begin $display("FAILED: T1 matched 5'b0101"); passed = 1'b0;end
8'b000001: begin $display("T1 matched 8'b000001"); end
default: begin $display("FAILED: T1 matched default"); passed = 1'b0;end
endcase
if (passed) $display("PASSED");
end
endmodule

View File

@ -370,6 +370,7 @@ br_gh1223c normal,-g2009 ivltests
br_gh1225a CE ivltests gold=br_gh1225a.gold
br_gh1225b CE ivltests gold=br_gh1225b.gold
br_gh1225c CE ivltests gold=br_gh1225c.gold
br_gh1237 normal ivltests
br_ml20150315 normal ivltests gold=br_ml_20150315.gold
br_ml20150321 CE ivltests
br_mw20171108 normal ivltests

View File

@ -862,6 +862,7 @@ br_gh793 normal,-pallowsigned=1 ivltests
br_gh1223a normal,-g2009,-pallowsigned=1 ivltests
br_gh1223b normal,-g2009,-pallowsigned=1 ivltests
br_gh1223c normal,-g2009,-pallowsigned=1 ivltests
br_gh1237 normal,-pallowsigned=1 ivltests
ca_mult normal,-pallowsigned=1 ivltests gold=ca_mult.gold
cast_int normal,-pallowsigned=1 ivltests
cfunc_assign_op_vec normal,-g2009,-pallowsigned=1 ivltests

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000-2021 Stephen Williams (steve@icarus.com)
* Copyright (c) 2000-2025 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@ -154,7 +154,8 @@ void NetCase::prune()
}
// Prune the case expression
expr_ = pad_to_width(unpadded_expr->dup_expr(), prune_width, *expr_);
expr_ = pad_to_width(unpadded_expr->dup_expr(), prune_width,
padded_expr->has_sign(), *expr_);
delete padded_expr;
// Prune the case item expressions