@@ -1240,6 +1240,71 @@ hw.module @moduloZeroDividend(in %arg0 : i32, out o1: i32, out o2: i32) {
12401240 hw.output %0 , %1 : i32 , i32
12411241}
12421242
1243+ // CHECK-LABEL: hw.module @divuPowerOfTwo
1244+ hw.module @divuPowerOfTwo (in %arg0 : i8 , out o1 : i8 , out o2 : i8 , out o3 : i8 , out o4 : i8 , out o5 : i8 ) {
1245+ // divu(x, 2) -> concat(0, extract(x, 1, 7))
1246+ // CHECK: [[EXT1:%.+]] = comb.extract %arg0 from 1 : (i8) -> i7
1247+ // CHECK-NEXT: [[RES1:%.+]] = comb.concat %false, [[EXT1]] : i1, i7
1248+ %c2 = hw.constant 2 : i8
1249+ %0 = comb.divu bin %arg0 , %c2 : i8
1250+
1251+ // divu(x, 4) -> concat(00, extract(x, 2, 6))
1252+ // CHECK-NEXT: [[EXT2:%.+]] = comb.extract %arg0 from 2 : (i8) -> i6
1253+ // CHECK-NEXT: [[RES2:%.+]] = comb.concat %c0_i2, [[EXT2]] : i2, i6
1254+ %c4 = hw.constant 4 : i8
1255+ %1 = comb.divu bin %arg0 , %c4 : i8
1256+
1257+ // divu(x, 16) -> concat(0000, extract(x, 4, 4))
1258+ // CHECK-NEXT: [[EXT4:%.+]] = comb.extract %arg0 from 4 : (i8) -> i4
1259+ // CHECK-NEXT: [[RES3:%.+]] = comb.concat %c0_i4, [[EXT4]] : i4, i4
1260+ %c16 = hw.constant 16 : i8
1261+ %2 = comb.divu bin %arg0 , %c16 : i8
1262+
1263+ // divu(x, 3) -> not canonicalized (not power of two)
1264+ // CHECK-NEXT: [[RES4:%.+]] = comb.divu bin %arg0, %c3_i8 : i8
1265+ %c3 = hw.constant 3 : i8
1266+ %3 = comb.divu bin %arg0 , %c3 : i8
1267+
1268+ // Make sure canonicalization does not happen if there is no bin flag.
1269+ // CHECK-NEXT: [[RES5:%.+]] = comb.divu %arg0, %c2_i8 : i8
1270+ %4 = comb.divu %arg0 , %c2 : i8
1271+
1272+ // CHECK: hw.output [[RES1]], [[RES2]], [[RES3]], [[RES4]], [[RES5]]
1273+ hw.output %0 , %1 , %2 , %3 , %4 : i8 , i8 , i8 , i8 , i8
1274+ }
1275+
1276+ // CHECK-LABEL: hw.module @moduPowerOfTwo
1277+ hw.module @moduPowerOfTwo (in %arg0 : i8 , out o1 : i8 , out o2 : i8 , out o3 : i8 , out o4 : i8 , out o5 : i8 ) {
1278+ // modu(x, 2) -> concat(0000000, extract(x, 0, 1))
1279+ // CHECK: [[EXT1:%.+]] = comb.extract %arg0 from 0 : (i8) -> i1
1280+ // CHECK-NEXT: [[RES1:%.+]] = comb.concat %c0_i7, [[EXT1]] : i7, i1
1281+ %c2 = hw.constant 2 : i8
1282+ %0 = comb.modu bin %arg0 , %c2 : i8
1283+
1284+ // modu(x, 4) -> concat(000000, extract(x, 0, 2))
1285+ // CHECK-NEXT: [[EXT2:%.+]] = comb.extract %arg0 from 0 : (i8) -> i2
1286+ // CHECK-NEXT: [[RES2:%.+]] = comb.concat %c0_i6, [[EXT2]] : i6, i2
1287+ %c4 = hw.constant 4 : i8
1288+ %1 = comb.modu bin %arg0 , %c4 : i8
1289+
1290+ // modu(x, 16) -> concat(0000, extract(x, 0, 4))
1291+ // CHECK-NEXT: [[EXT4:%.+]] = comb.extract %arg0 from 0 : (i8) -> i4
1292+ // CHECK-NEXT: [[RES3:%.+]] = comb.concat %c0_i4, [[EXT4]] : i4, i4
1293+ %c16 = hw.constant 16 : i8
1294+ %2 = comb.modu bin %arg0 , %c16 : i8
1295+
1296+ // modu(x, 3) -> not canonicalized (not power of two)
1297+ // CHECK-NEXT: [[RES4:%.+]] = comb.modu bin %arg0, %c3_i8 : i8
1298+ %c3 = hw.constant 3 : i8
1299+ %3 = comb.modu bin %arg0 , %c3 : i8
1300+
1301+ // Make sure canonicalization does not happen if there is no bin flag.
1302+ // CHECK-NEXT: [[RES5:%.+]] = comb.modu %arg0, %c2_i8 : i8
1303+ %4 = comb.modu %arg0 , %c2 : i8
1304+ // CHECK: hw.output [[RES1]], [[RES2]], [[RES3]], [[RES4]], [[RES5]]
1305+ hw.output %0 , %1 , %2 , %3 , %4 : i8 , i8 , i8 , i8 , i8
1306+ }
1307+
12431308// CHECK-LABEL: hw.module @orWithNegation
12441309hw.module @orWithNegation (in %arg0 : i32 , out o1 : i32 ) {
12451310 // CHECK: [[ALLONES:%.*]] = hw.constant -1 : i32
0 commit comments