Skip to content

Commit 216787c

Browse files
authored
[mlir][arith] Add tests for i0 canonicalization (#89665)
Before #87193, the canonicalizer in arith crashed when attempting signed extension on an i0 value. To hopefully avoid it happening again, this PR introduces tests for canonicalization of arith operations with i0 values, focusing on operations related to bit width or signedness.
1 parent 8ad092f commit 216787c

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

mlir/test/Dialect/Arith/canonicalize.mlir

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2831,6 +2831,87 @@ func.func @unsignedExtendConstantResource() -> tensor<i16> {
28312831
return %ext : tensor<i16>
28322832
}
28332833

2834+
// CHECK-LABEL: @extsi_i0
2835+
// CHECK: %[[ZERO:.*]] = arith.constant 0 : i16
2836+
// CHECK: return %[[ZERO]] : i16
2837+
func.func @extsi_i0() -> i16 {
2838+
%c0 = arith.constant 0 : i0
2839+
%extsi = arith.extsi %c0 : i0 to i16
2840+
return %extsi : i16
2841+
}
2842+
2843+
// CHECK-LABEL: @extui_i0
2844+
// CHECK: %[[ZERO:.*]] = arith.constant 0 : i16
2845+
// CHECK: return %[[ZERO]] : i16
2846+
func.func @extui_i0() -> i16 {
2847+
%c0 = arith.constant 0 : i0
2848+
%extui = arith.extui %c0 : i0 to i16
2849+
return %extui : i16
2850+
}
2851+
2852+
// CHECK-LABEL: @trunc_i0
2853+
// CHECK: %[[ZERO:.*]] = arith.constant 0 : i0
2854+
// CHECK: return %[[ZERO]] : i0
2855+
func.func @trunc_i0() -> i0 {
2856+
%cFF = arith.constant 0xFF : i8
2857+
%trunc = arith.trunci %cFF : i8 to i0
2858+
return %trunc : i0
2859+
}
2860+
2861+
// CHECK-LABEL: @shli_i0
2862+
// CHECK: %[[ZERO:.*]] = arith.constant 0 : i0
2863+
// CHECK: return %[[ZERO]] : i0
2864+
func.func @shli_i0() -> i0 {
2865+
%c0 = arith.constant 0 : i0
2866+
%shli = arith.shli %c0, %c0 : i0
2867+
return %shli : i0
2868+
}
2869+
2870+
// CHECK-LABEL: @shrsi_i0
2871+
// CHECK: %[[ZERO:.*]] = arith.constant 0 : i0
2872+
// CHECK: return %[[ZERO]] : i0
2873+
func.func @shrsi_i0() -> i0 {
2874+
%c0 = arith.constant 0 : i0
2875+
%shrsi = arith.shrsi %c0, %c0 : i0
2876+
return %shrsi : i0
2877+
}
2878+
2879+
// CHECK-LABEL: @shrui_i0
2880+
// CHECK: %[[ZERO:.*]] = arith.constant 0 : i0
2881+
// CHECK: return %[[ZERO]] : i0
2882+
func.func @shrui_i0() -> i0 {
2883+
%c0 = arith.constant 0 : i0
2884+
%shrui = arith.shrui %c0, %c0 : i0
2885+
return %shrui : i0
2886+
}
2887+
2888+
// CHECK-LABEL: @maxsi_i0
2889+
// CHECK: %[[ZERO:.*]] = arith.constant 0 : i0
2890+
// CHECK: return %[[ZERO]] : i0
2891+
func.func @maxsi_i0() -> i0 {
2892+
%c0 = arith.constant 0 : i0
2893+
%maxsi = arith.maxsi %c0, %c0 : i0
2894+
return %maxsi : i0
2895+
}
2896+
2897+
// CHECK-LABEL: @minsi_i0
2898+
// CHECK: %[[ZERO:.*]] = arith.constant 0 : i0
2899+
// CHECK: return %[[ZERO]] : i0
2900+
func.func @minsi_i0() -> i0 {
2901+
%c0 = arith.constant 0 : i0
2902+
%minsi = arith.minsi %c0, %c0 : i0
2903+
return %minsi : i0
2904+
}
2905+
2906+
// CHECK-LABEL: @mulsi_extended_i0
2907+
// CHECK: %[[ZERO:.*]] = arith.constant 0 : i0
2908+
// CHECK: return %[[ZERO]], %[[ZERO]] : i0
2909+
func.func @mulsi_extended_i0() -> (i0, i0) {
2910+
%c0 = arith.constant 0 : i0
2911+
%mulsi_extended:2 = arith.mulsi_extended %c0, %c0 : i0
2912+
return %mulsi_extended#0, %mulsi_extended#1 : i0, i0
2913+
}
2914+
28342915
{-#
28352916
dialect_resources: {
28362917
builtin: {

0 commit comments

Comments
 (0)