@@ -1960,3 +1960,103 @@ hw.module @issue9403(in %sel: i1, out out1: ui1) {
19601960 %mux1 = comb.mux %sel , %true , %false : ui1
19611961 hw.output %mux1 : ui1
19621962}
1963+
1964+
1965+ // CHECK-LABEL: @truth_table_constant_true
1966+ hw.module @truth_table_constant_true (in %a: i1 , in %b: i1 , out out : i1 ) {
1967+ // Truth table that is always true (all ones)
1968+ // CHECK-NEXT: [[TRUE:%.+]] = hw.constant true
1969+ // CHECK-NEXT: hw.output [[TRUE]]
1970+ %0 = comb.truth_table %a , %b -> [true , true , true , true ]
1971+ hw.output %0 : i1
1972+ }
1973+
1974+ // CHECK-LABEL: @truth_table_constant_false
1975+ hw.module @truth_table_constant_false (in %a: i1 , in %b: i1 , out out : i1 ) {
1976+ // Truth table that is always false (all zeros)
1977+ // CHECK-NEXT: [[FALSE:%.+]] = hw.constant false
1978+ // CHECK-NEXT: hw.output [[FALSE]]
1979+ %0 = comb.truth_table %a , %b -> [false , false , false , false ]
1980+ hw.output %0 : i1
1981+ }
1982+
1983+ // CHECK-LABEL: @truth_table_identity
1984+ hw.module @truth_table_identity (in %a: i1 , in %b: i1 , in %c: i1 , out out : i1 ) {
1985+ // Truth table that depends only on %a
1986+ // Pattern: [0,0,0,0,1,1,1,1] means output follows first input
1987+ // CHECK-NEXT: hw.output %a
1988+ %0 = comb.truth_table %a , %b , %c -> [false , false , false , false , true , true , true , true ]
1989+ hw.output %0 : i1
1990+ }
1991+
1992+ // CHECK-LABEL: @truth_table_inverted
1993+ hw.module @truth_table_inverted (in %a: i1 , in %b: i1 , in %c: i1 , out out : i1 ) {
1994+ // Truth table that depends only on %a (inverted)
1995+ // Pattern: [1,1,1,1,0,0,0,0] means output is NOT of first input
1996+ // CHECK-NEXT: %true = hw.constant true
1997+ // CHECK-NEXT: [[NOT:%.+]] = comb.xor %a, %true
1998+ // CHECK-NEXT: hw.output [[NOT]]
1999+ %0 = comb.truth_table %a , %b , %c -> [true , true , true , true , false , false , false , false ]
2000+ hw.output %0 : i1
2001+ }
2002+
2003+ // CHECK-LABEL: @truth_table_middle_input_identity
2004+ hw.module @truth_table_middle_input_identity (in %a: i1 , in %b: i1 , in %c: i1 , out out : i1 ) {
2005+ // Truth table that depends only on %b (middle input, identity)
2006+ // Pattern: [0,0,1,1,0,0,1,1] means output follows second input
2007+ // CHECK-NEXT: hw.output %b
2008+ %0 = comb.truth_table %a , %b , %c -> [false , false , true , true , false , false , true , true ]
2009+ hw.output %0 : i1
2010+ }
2011+
2012+ // CHECK-LABEL: @truth_table_middle_input_inverted
2013+ hw.module @truth_table_middle_input_inverted (in %a: i1 , in %b: i1 , in %c: i1 , out out : i1 ) {
2014+ // Truth table that depends only on %b (middle input, inverted)
2015+ // Pattern: [1,1,0,0,1,1,0,0] means output is NOT of second input
2016+ // CHECK-NEXT: %true = hw.constant true
2017+ // CHECK-NEXT: [[NOT:%.+]] = comb.xor %b, %true
2018+ // CHECK-NEXT: hw.output [[NOT]]
2019+ %0 = comb.truth_table %a , %b , %c -> [true , true , false , false , true , true , false , false ]
2020+ hw.output %0 : i1
2021+ }
2022+
2023+ // CHECK-LABEL: @truth_table_last_input_identity
2024+ hw.module @truth_table_last_input_identity (in %a: i1 , in %b: i1 , in %c: i1 , out out : i1 ) {
2025+ // Truth table that depends only on %c (last input, identity)
2026+ // Pattern: [0,1,0,1,0,1,0,1] means output follows third input
2027+ // CHECK-NEXT: hw.output %c
2028+ %0 = comb.truth_table %a , %b , %c -> [false , true , false , true , false , true , false , true ]
2029+ hw.output %0 : i1
2030+ }
2031+
2032+ // CHECK-LABEL: @truth_table_last_input_inverted
2033+ hw.module @truth_table_last_input_inverted (in %a: i1 , in %b: i1 , in %c: i1 , out out : i1 ) {
2034+ // Truth table that depends only on %c (last input, inverted)
2035+ // Pattern: [1,0,1,0,1,0,1,0] means output is NOT of third input
2036+ // CHECK-NEXT: %true = hw.constant true
2037+ // CHECK-NEXT: [[NOT:%.+]] = comb.xor %c, %true
2038+ // CHECK-NEXT: hw.output [[NOT]]
2039+ %0 = comb.truth_table %a , %b , %c -> [true , false , true , false , true , false , true , false ]
2040+ hw.output %0 : i1
2041+ }
2042+
2043+ // CHECK-LABEL: @truth_table_two_input_non_foldable
2044+ hw.module @truth_table_two_input_non_foldable (in %a: i1 , in %b: i1 , out out : i1 ) {
2045+ // Truth table depends on both inputs, Should not be canonicalized
2046+ // CHECK-NEXT: %0 = comb.truth_table %a, %b -> [false, false, false, true]
2047+ // CHECK-NEXT: hw.output %0
2048+ %0 = comb.truth_table %a , %b -> [false , false , false , true ]
2049+ hw.output %0 : i1
2050+ }
2051+
2052+ // CHECK-LABEL: @truth_table_with_extract_operations
2053+ hw.module @truth_table_with_extract_operations (in %c: i3 , out out : i1 ) {
2054+ // Truth table depends only on first input (%2 = LSB of %c)
2055+ // CHECK: [[TMP:%.+]] = comb.extract %c from 0
2056+ // CHECK: hw.output [[TMP]]
2057+ %0 = comb.extract %c from 2 : (i3 ) -> i1
2058+ %1 = comb.extract %c from 1 : (i3 ) -> i1
2059+ %2 = comb.extract %c from 0 : (i3 ) -> i1
2060+ %3 = comb.truth_table %2 , %0 , %1 -> [false , false , false , false , true , true , true , true ]
2061+ hw.output %3 : i1
2062+ }
0 commit comments