@@ -1046,3 +1046,112 @@ func.func @sitofp_i64_f64_vector(%a : vector<3xi64>) -> vector<3xf64> {
1046
1046
%r = arith.sitofp %a : vector <3 xi64 > to vector <3 xf64 >
1047
1047
return %r : vector <3 xf64 >
1048
1048
}
1049
+
1050
+ // CHECK-LABEL: func @fptoui_i64_f64
1051
+ // CHECK-SAME: ([[ARG:%.+]]: f64) -> vector<2xi32>
1052
+ // CHECK-NEXT: [[POW:%.+]] = arith.constant 0x41F0000000000000 : f64
1053
+ // CHECK-NEXT: [[DIV:%.+]] = arith.divf [[ARG]], [[POW]] : f64
1054
+ // CHECK-NEXT: [[HIGHHALF:%.+]] = arith.fptoui [[DIV]] : f64 to i32
1055
+ // CHECK-NEXT: [[REM:%.+]] = arith.remf [[ARG]], [[POW]] : f64
1056
+ // CHECK-NEXT: [[LOWHALF:%.+]] = arith.fptoui [[REM]] : f64 to i32
1057
+ // CHECK: %{{.+}} = vector.insert [[LOWHALF]], %{{.+}} [0]
1058
+ // CHECK-NEXT: [[RESVEC:%.+]] = vector.insert [[HIGHHALF]], %{{.+}} [1]
1059
+ // CHECK: return [[RESVEC]] : vector<2xi32>
1060
+ func.func @fptoui_i64_f64 (%a : f64 ) -> i64 {
1061
+ %r = arith.fptoui %a : f64 to i64
1062
+ return %r : i64
1063
+ }
1064
+
1065
+ // CHECK-LABEL: func @fptoui_i64_f64_vector
1066
+ // CHECK-SAME: ([[ARG:%.+]]: vector<3xf64>) -> vector<3x2xi32>
1067
+ // CHECK-NEXT: [[POW:%.+]] = arith.constant dense<0x41F0000000000000> : vector<3xf64>
1068
+ // CHECK-NEXT: [[DIV:%.+]] = arith.divf [[ARG]], [[POW]] : vector<3xf64>
1069
+ // CHECK-NEXT: [[HIGHHALF:%.+]] = arith.fptoui [[DIV]] : vector<3xf64> to vector<3xi32>
1070
+ // CHECK-NEXT: [[REM:%.+]] = arith.remf [[ARG]], [[POW]] : vector<3xf64>
1071
+ // CHECK-NEXT: [[LOWHALF:%.+]] = arith.fptoui [[REM]] : vector<3xf64> to vector<3xi32>
1072
+ // CHECK-DAG: [[HIGHHALFX1:%.+]] = vector.shape_cast [[HIGHHALF]] : vector<3xi32> to vector<3x1xi32>
1073
+ // CHECK-DAG: [[LOWHALFX1:%.+]] = vector.shape_cast [[LOWHALF]] : vector<3xi32> to vector<3x1xi32>
1074
+ // CHECK: %{{.+}} = vector.insert_strided_slice [[LOWHALFX1]], %{{.+}} {offsets = [0, 0], strides = [1, 1]}
1075
+ // CHECK-NEXT: [[RESVEC:%.+]] = vector.insert_strided_slice [[HIGHHALFX1]], %{{.+}} {offsets = [0, 1], strides = [1, 1]}
1076
+ // CHECK: return [[RESVEC]] : vector<3x2xi32>
1077
+ func.func @fptoui_i64_f64_vector (%a : vector <3 xf64 >) -> vector <3 xi64 > {
1078
+ %r = arith.fptoui %a : vector <3 xf64 > to vector <3 xi64 >
1079
+ return %r : vector <3 xi64 >
1080
+ }
1081
+
1082
+ // This generates lines that are already verified by other patterns.
1083
+ // We do not re-verify these and just check for the wrapper around fptoui by following its low part.
1084
+ // CHECK-LABEL: func @fptosi_i64_f64
1085
+ // CHECK-SAME: ([[ARG:%.+]]: f64) -> vector<2xi32>
1086
+ // CHECK: [[ZEROCST:%.+]] = arith.constant 0.000000e+00 : f64
1087
+ // CHECK: [[ZEROCSTINT:%.+]] = arith.constant dense<0> : vector<2xi32>
1088
+ // CHECK-NEXT: [[ISNEGATIVE:%.+]] = arith.cmpf olt, [[ARG]], [[ZEROCST]] : f64
1089
+ // CHECK-NEXT: [[NEGATED:%.+]] = arith.negf [[ARG]] : f64
1090
+ // CHECK-NEXT: [[ABSVALUE:%.+]] = arith.select [[ISNEGATIVE]], [[NEGATED]], [[ARG]] : f64
1091
+ // CHECK-NEXT: [[POW:%.+]] = arith.constant 0x41F0000000000000 : f64
1092
+ // CHECK-NEXT: [[DIV:%.+]] = arith.divf [[ABSVALUE]], [[POW]] : f64
1093
+ // CHECK-NEXT: [[HIGHHALF:%.+]] = arith.fptoui [[DIV]] : f64 to i32
1094
+ // CHECK-NEXT: [[REM:%.+]] = arith.remf [[ABSVALUE]], [[POW]] : f64
1095
+ // CHECK-NEXT: [[LOWHALF:%.+]] = arith.fptoui [[REM]] : f64 to i32
1096
+ // CHECK: vector.insert [[LOWHALF]], %{{.+}} [0] : i32 into vector<2xi32>
1097
+ // CHECK-NEXT: [[FPTOUIRESVEC:%.+]] = vector.insert [[HIGHHALF]]
1098
+ // CHECK: [[ZEROCSTINTHALF:%.+]] = vector.extract [[ZEROCSTINT]][0] : i32 from vector<2xi32>
1099
+ // CHECK: [[SUB:%.+]] = arith.subi [[ZEROCSTINTHALF]], %{{.+}} : i32
1100
+ // CHECK-NEXT: arith.cmpi ult, [[ZEROCSTINTHALF]], %{{.+}} : i32
1101
+ // CHECK-NEXT: arith.extui
1102
+ // CHECK-NEXT: arith.subi
1103
+ // CHECK-NEXT: arith.subi
1104
+ // CHECK: vector.insert [[SUB]]
1105
+ // CHECK: [[SUBVEC:%.+]] = vector.insert
1106
+ // CHECK: [[SUB:%.+]] = vector.extract [[SUBVEC]][0] : i32 from vector<2xi32>
1107
+ // CHECK: [[LOWRES:%.+]] = vector.extract [[FPTOUIRESVEC]][0] : i32 from vector<2xi32>
1108
+ // CHECK: [[ABSRES:%.+]] = arith.select [[ISNEGATIVE]], [[SUB]], [[LOWRES]] : i32
1109
+ // CHECK-NEXT: arith.select [[ISNEGATIVE]]
1110
+ // CHECK: vector.insert [[ABSRES]]
1111
+ // CHECK-NEXT: [[ABSRESVEC:%.+]] = vector.insert
1112
+ // CHECK-NEXT: return [[ABSRESVEC]] : vector<2xi32>
1113
+ func.func @fptosi_i64_f64 (%a : f64 ) -> i64 {
1114
+ %r = arith.fptosi %a : f64 to i64
1115
+ return %r : i64
1116
+ }
1117
+
1118
+ // Same as the non-vector one, we don't re-verify.
1119
+ // CHECK-LABEL: func @fptosi_i64_f64_vector
1120
+ // CHECK-SAME: ([[ARG:%.+]]: vector<3xf64>) -> vector<3x2xi32>
1121
+ // CHECK-NEXT: [[ZEROCST:%.+]] = arith.constant dense<0.000000e+00> : vector<3xf64>
1122
+ // CHECK-NEXT: [[ZEROCSTINT:%.+]] = arith.constant dense<0> : vector<3x2xi32>
1123
+ // CHECK-NEXT: [[ISNEGATIVE:%.+]] = arith.cmpf olt, [[ARG]], [[ZEROCST]] : vector<3xf64>
1124
+ // CHECK-NEXT: [[NEGATED:%.+]] = arith.negf [[ARG]] : vector<3xf64>
1125
+ // CHECK-NEXT: [[ABSVALUE:%.+]] = arith.select [[ISNEGATIVE]], [[NEGATED]], [[ARG]] : vector<3xi1>, vector<3xf64>
1126
+ // CHECK-NEXT: [[POW:%.+]] = arith.constant dense<0x41F0000000000000> : vector<3xf64>
1127
+ // CHECK-NEXT: [[DIV:%.+]] = arith.divf [[ABSVALUE]], [[POW]] : vector<3xf64>
1128
+ // CHECK-NEXT: [[HIGHHALF:%.+]] = arith.fptoui [[DIV]] : vector<3xf64> to vector<3xi32>
1129
+ // CHECK-NEXT: [[REM:%.+]] = arith.remf [[ABSVALUE]], [[POW]] : vector<3xf64>
1130
+ // CHECK-NEXT: [[LOWHALF:%.+]] = arith.fptoui [[REM]] : vector<3xf64> to vector<3xi32>
1131
+ // CHECK-NEXT: [[HIGHHALFX1:%.+]] = vector.shape_cast [[HIGHHALF]] : vector<3xi32> to vector<3x1xi32>
1132
+ // CHECK-NEXT: [[LOWHALFX1:%.+]] = vector.shape_cast [[LOWHALF]] : vector<3xi32> to vector<3x1xi32>
1133
+ // CHECK: vector.insert_strided_slice [[LOWHALFX1]], %{{.+}} {offsets = [0, 0], strides = [1, 1]} : vector<3x1xi32> into vector<3x2xi32>
1134
+ // CHECK-NEXT: [[FPTOUIRESVEC:%.+]] = vector.insert_strided_slice [[HIGHHALFX1]]
1135
+ // CHECK: [[ZEROCSTINTHALF:%.+]] = vector.extract_strided_slice [[ZEROCSTINT]]
1136
+ // CHECK-SAME: {offsets = [0, 0], sizes = [3, 1], strides = [1, 1]} : vector<3x2xi32> to vector<3x1xi32>
1137
+ // CHECK: [[SUB:%.+]] = arith.subi [[ZEROCSTINTHALF]], %{{.+}} : vector<3x1xi32>
1138
+ // CHECK-NEXT: arith.cmpi ult, [[ZEROCSTINTHALF]], %{{.+}} : vector<3x1xi32>
1139
+ // CHECK-NEXT: arith.extui
1140
+ // CHECK-NEXT: arith.subi
1141
+ // CHECK-NEXT: arith.subi
1142
+ // CHECK: vector.insert_strided_slice [[SUB]]
1143
+ // CHECK-NEXT: [[SUBVEC:%.+]] = vector.insert_strided_slice
1144
+ // CHECK: [[SUB:%.+]] = vector.extract_strided_slice [[SUBVEC]]
1145
+ // CHECK-SAME: {offsets = [0, 0], sizes = [3, 1], strides = [1, 1]} : vector<3x2xi32> to vector<3x1xi32>
1146
+ // CHECK: [[LOWRES:%.+]] = vector.extract_strided_slice [[FPTOUIRESVEC]]
1147
+ // CHECK-SAME: {offsets = [0, 0], sizes = [3, 1], strides = [1, 1]} : vector<3x2xi32> to vector<3x1xi32>
1148
+ // CHECK: [[ISNEGATIVEX1:%.+]] = vector.shape_cast [[ISNEGATIVE]] : vector<3xi1> to vector<3x1xi1>
1149
+ // CHECK: [[ABSRES:%.+]] = arith.select [[ISNEGATIVEX1]], [[SUB]], [[LOWRES]] : vector<3x1xi1>, vector<3x1xi32>
1150
+ // CHECK-NEXT: arith.select [[ISNEGATIVEX1]]
1151
+ // CHECK: vector.insert_strided_slice [[ABSRES]]
1152
+ // CHECK-NEXT: [[ABSRESVEC:%.+]] = vector.insert_strided_slice
1153
+ // CHECK-NEXT: return [[ABSRESVEC]] : vector<3x2xi32>
1154
+ func.func @fptosi_i64_f64_vector (%a : vector <3 xf64 >) -> vector <3 xi64 > {
1155
+ %r = arith.fptosi %a : vector <3 xf64 > to vector <3 xi64 >
1156
+ return %r : vector <3 xi64 >
1157
+ }
0 commit comments