1 // RUN: mlir-opt %s -split-input-file -pass-pipeline="builtin.module(convert-math-to-funcs)" | FileCheck %s
5 // CHECK-LABEL: func @ipowi(
6 // CHECK-SAME: %[[ARG0:.+]]: i64,
7 // CHECK-SAME: %[[ARG1:.+]]: i64)
8 func.func @ipowi(%arg0: i64, %arg1: i64) {
9 // CHECK: call @__mlir_math_ipowi_i64(%[[ARG0]], %[[ARG1]]) : (i64, i64) -> i64
10 %0 = math.ipowi %arg0, %arg1 : i64
14 // CHECK-LABEL: func.func private @__mlir_math_ipowi_i64(
15 // CHECK-SAME: %[[VAL_0:.*]]: i64,
16 // CHECK-SAME: %[[VAL_1:.*]]: i64) -> i64
17 // CHECK-SAME: attributes {llvm.linkage = #llvm.linkage<linkonce_odr>} {
18 // CHECK: %[[VAL_2:.*]] = arith.constant 0 : i64
19 // CHECK: %[[VAL_3:.*]] = arith.constant 1 : i64
20 // CHECK: %[[VAL_4:.*]] = arith.constant -1 : i64
21 // CHECK: %[[VAL_5:.*]] = arith.cmpi eq, %[[VAL_1]], %[[VAL_2]] : i64
22 // CHECK: cf.cond_br %[[VAL_5]], ^bb1, ^bb2
24 // CHECK: return %[[VAL_3]] : i64
26 // CHECK: %[[VAL_6:.*]] = arith.cmpi sle, %[[VAL_1]], %[[VAL_2]] : i64
27 // CHECK: cf.cond_br %[[VAL_6]], ^bb3, ^bb12(%[[VAL_3]], %[[VAL_0]], %[[VAL_1]] : i64, i64, i64)
29 // CHECK: %[[VAL_7:.*]] = arith.cmpi eq, %[[VAL_0]], %[[VAL_2]] : i64
30 // CHECK: cf.cond_br %[[VAL_7]], ^bb4, ^bb5
32 // CHECK: %[[VAL_8:.*]] = arith.divsi %[[VAL_3]], %[[VAL_2]] : i64
33 // CHECK: return %[[VAL_8]] : i64
35 // CHECK: %[[VAL_9:.*]] = arith.cmpi eq, %[[VAL_0]], %[[VAL_3]] : i64
36 // CHECK: cf.cond_br %[[VAL_9]], ^bb6, ^bb7
38 // CHECK: return %[[VAL_3]] : i64
40 // CHECK: %[[VAL_10:.*]] = arith.cmpi eq, %[[VAL_0]], %[[VAL_4]] : i64
41 // CHECK: cf.cond_br %[[VAL_10]], ^bb8, ^bb11
43 // CHECK: %[[VAL_11:.*]] = arith.andi %[[VAL_1]], %[[VAL_3]] : i64
44 // CHECK: %[[VAL_12:.*]] = arith.cmpi ne, %[[VAL_11]], %[[VAL_2]] : i64
45 // CHECK: cf.cond_br %[[VAL_12]], ^bb9, ^bb10
47 // CHECK: return %[[VAL_4]] : i64
49 // CHECK: return %[[VAL_3]] : i64
51 // CHECK: return %[[VAL_2]] : i64
52 // CHECK: ^bb12(%[[VAL_13:.*]]: i64, %[[VAL_14:.*]]: i64, %[[VAL_15:.*]]: i64):
53 // CHECK: %[[VAL_16:.*]] = arith.andi %[[VAL_15]], %[[VAL_3]] : i64
54 // CHECK: %[[VAL_17:.*]] = arith.cmpi ne, %[[VAL_16]], %[[VAL_2]] : i64
55 // CHECK: cf.cond_br %[[VAL_17]], ^bb13, ^bb14(%[[VAL_13]] : i64)
57 // CHECK: %[[VAL_18:.*]] = arith.muli %[[VAL_13]], %[[VAL_14]] : i64
58 // CHECK: cf.br ^bb14(%[[VAL_18]] : i64)
59 // CHECK: ^bb14(%[[VAL_19:.*]]: i64):
60 // CHECK: %[[VAL_20:.*]] = arith.shrui %[[VAL_15]], %[[VAL_3]] : i64
61 // CHECK: %[[VAL_21:.*]] = arith.cmpi eq, %[[VAL_20]], %[[VAL_2]] : i64
62 // CHECK: cf.cond_br %[[VAL_21]], ^bb15, ^bb16
64 // CHECK: return %[[VAL_19]] : i64
66 // CHECK: %[[VAL_22:.*]] = arith.muli %[[VAL_14]], %[[VAL_14]] : i64
67 // CHECK: cf.br ^bb12(%[[VAL_19]], %[[VAL_22]], %[[VAL_20]] : i64, i64, i64)
72 // CHECK-LABEL: func @ipowi(
73 // CHECK-SAME: %[[ARG0:.+]]: i8,
74 // CHECK-SAME: %[[ARG1:.+]]: i8)
75 // CHECK: call @__mlir_math_ipowi_i8(%[[ARG0]], %[[ARG1]]) : (i8, i8) -> i8
76 func.func @ipowi(%arg0: i8, %arg1: i8) {
77 %0 = math.ipowi %arg0, %arg1 : i8
81 // CHECK-LABEL: func.func private @__mlir_math_ipowi_i8(
82 // CHECK-SAME: %[[VAL_0:.*]]: i8,
83 // CHECK-SAME: %[[VAL_1:.*]]: i8) -> i8
84 // CHECK-SAME: attributes {llvm.linkage = #llvm.linkage<linkonce_odr>} {
85 // CHECK: %[[VAL_2:.*]] = arith.constant 0 : i8
86 // CHECK: %[[VAL_3:.*]] = arith.constant 1 : i8
87 // CHECK: %[[VAL_4:.*]] = arith.constant -1 : i8
88 // CHECK: %[[VAL_5:.*]] = arith.cmpi eq, %[[VAL_1]], %[[VAL_2]] : i8
89 // CHECK: cf.cond_br %[[VAL_5]], ^bb1, ^bb2
91 // CHECK: return %[[VAL_3]] : i8
93 // CHECK: %[[VAL_6:.*]] = arith.cmpi sle, %[[VAL_1]], %[[VAL_2]] : i8
94 // CHECK: cf.cond_br %[[VAL_6]], ^bb3, ^bb12(%[[VAL_3]], %[[VAL_0]], %[[VAL_1]] : i8, i8, i8)
96 // CHECK: %[[VAL_7:.*]] = arith.cmpi eq, %[[VAL_0]], %[[VAL_2]] : i8
97 // CHECK: cf.cond_br %[[VAL_7]], ^bb4, ^bb5
99 // CHECK: %[[VAL_8:.*]] = arith.divsi %[[VAL_3]], %[[VAL_2]] : i8
100 // CHECK: return %[[VAL_8]] : i8
102 // CHECK: %[[VAL_9:.*]] = arith.cmpi eq, %[[VAL_0]], %[[VAL_3]] : i8
103 // CHECK: cf.cond_br %[[VAL_9]], ^bb6, ^bb7
105 // CHECK: return %[[VAL_3]] : i8
107 // CHECK: %[[VAL_10:.*]] = arith.cmpi eq, %[[VAL_0]], %[[VAL_4]] : i8
108 // CHECK: cf.cond_br %[[VAL_10]], ^bb8, ^bb11
110 // CHECK: %[[VAL_11:.*]] = arith.andi %[[VAL_1]], %[[VAL_3]] : i8
111 // CHECK: %[[VAL_12:.*]] = arith.cmpi ne, %[[VAL_11]], %[[VAL_2]] : i8
112 // CHECK: cf.cond_br %[[VAL_12]], ^bb9, ^bb10
114 // CHECK: return %[[VAL_4]] : i8
116 // CHECK: return %[[VAL_3]] : i8
118 // CHECK: return %[[VAL_2]] : i8
119 // CHECK: ^bb12(%[[VAL_13:.*]]: i8, %[[VAL_14:.*]]: i8, %[[VAL_15:.*]]: i8):
120 // CHECK: %[[VAL_16:.*]] = arith.andi %[[VAL_15]], %[[VAL_3]] : i8
121 // CHECK: %[[VAL_17:.*]] = arith.cmpi ne, %[[VAL_16]], %[[VAL_2]] : i8
122 // CHECK: cf.cond_br %[[VAL_17]], ^bb13, ^bb14(%[[VAL_13]] : i8)
124 // CHECK: %[[VAL_18:.*]] = arith.muli %[[VAL_13]], %[[VAL_14]] : i8
125 // CHECK: cf.br ^bb14(%[[VAL_18]] : i8)
126 // CHECK: ^bb14(%[[VAL_19:.*]]: i8):
127 // CHECK: %[[VAL_20:.*]] = arith.shrui %[[VAL_15]], %[[VAL_3]] : i8
128 // CHECK: %[[VAL_21:.*]] = arith.cmpi eq, %[[VAL_20]], %[[VAL_2]] : i8
129 // CHECK: cf.cond_br %[[VAL_21]], ^bb15, ^bb16
131 // CHECK: return %[[VAL_19]] : i8
133 // CHECK: %[[VAL_22:.*]] = arith.muli %[[VAL_14]], %[[VAL_14]] : i8
134 // CHECK: cf.br ^bb12(%[[VAL_19]], %[[VAL_22]], %[[VAL_20]] : i8, i8, i8)
139 // CHECK-LABEL: func.func @ipowi_vec(
140 // CHECK-SAME: %[[VAL_0:.*]]: vector<2x3xi64>,
141 // CHECK-SAME: %[[VAL_1:.*]]: vector<2x3xi64>) {
142 func.func @ipowi_vec(%arg0: vector<2x3xi64>, %arg1: vector<2x3xi64>) {
143 // CHECK: %[[CST:.*]] = arith.constant dense<0> : vector<2x3xi64>
144 // CHECK: %[[B00:.*]] = vector.extract %[[VAL_0]][0, 0] : i64 from vector<2x3xi64>
145 // CHECK: %[[E00:.*]] = vector.extract %[[VAL_1]][0, 0] : i64 from vector<2x3xi64>
146 // CHECK: %[[R00:.*]] = call @__mlir_math_ipowi_i64(%[[B00]], %[[E00]]) : (i64, i64) -> i64
147 // CHECK: %[[TMP00:.*]] = vector.insert %[[R00]], %[[CST]] [0, 0] : i64 into vector<2x3xi64>
148 // CHECK: %[[B01:.*]] = vector.extract %[[VAL_0]][0, 1] : i64 from vector<2x3xi64>
149 // CHECK: %[[E01:.*]] = vector.extract %[[VAL_1]][0, 1] : i64 from vector<2x3xi64>
150 // CHECK: %[[R01:.*]] = call @__mlir_math_ipowi_i64(%[[B01]], %[[E01]]) : (i64, i64) -> i64
151 // CHECK: %[[TMP01:.*]] = vector.insert %[[R01]], %[[TMP00]] [0, 1] : i64 into vector<2x3xi64>
152 // CHECK: %[[B02:.*]] = vector.extract %[[VAL_0]][0, 2] : i64 from vector<2x3xi64>
153 // CHECK: %[[E02:.*]] = vector.extract %[[VAL_1]][0, 2] : i64 from vector<2x3xi64>
154 // CHECK: %[[R02:.*]] = call @__mlir_math_ipowi_i64(%[[B02]], %[[E02]]) : (i64, i64) -> i64
155 // CHECK: %[[TMP02:.*]] = vector.insert %[[R02]], %[[TMP01]] [0, 2] : i64 into vector<2x3xi64>
156 // CHECK: %[[B10:.*]] = vector.extract %[[VAL_0]][1, 0] : i64 from vector<2x3xi64>
157 // CHECK: %[[E10:.*]] = vector.extract %[[VAL_1]][1, 0] : i64 from vector<2x3xi64>
158 // CHECK: %[[R10:.*]] = call @__mlir_math_ipowi_i64(%[[B10]], %[[E10]]) : (i64, i64) -> i64
159 // CHECK: %[[TMP10:.*]] = vector.insert %[[R10]], %[[TMP02]] [1, 0] : i64 into vector<2x3xi64>
160 // CHECK: %[[B11:.*]] = vector.extract %[[VAL_0]][1, 1] : i64 from vector<2x3xi64>
161 // CHECK: %[[E11:.*]] = vector.extract %[[VAL_1]][1, 1] : i64 from vector<2x3xi64>
162 // CHECK: %[[R11:.*]] = call @__mlir_math_ipowi_i64(%[[B11]], %[[E11]]) : (i64, i64) -> i64
163 // CHECK: %[[TMP11:.*]] = vector.insert %[[R11]], %[[TMP10]] [1, 1] : i64 into vector<2x3xi64>
164 // CHECK: %[[B12:.*]] = vector.extract %[[VAL_0]][1, 2] : i64 from vector<2x3xi64>
165 // CHECK: %[[E12:.*]] = vector.extract %[[VAL_1]][1, 2] : i64 from vector<2x3xi64>
166 // CHECK: %[[R12:.*]] = call @__mlir_math_ipowi_i64(%[[B12]], %[[E12]]) : (i64, i64) -> i64
167 // CHECK: %[[TMP12:.*]] = vector.insert %[[R12]], %[[TMP11]] [1, 2] : i64 into vector<2x3xi64>
170 %0 = math.ipowi %arg0, %arg1 : vector<2x3xi64>
176 // Check that index is not converted
178 // CHECK-LABEL: func.func @ipowi_index
180 func.func @ipowi_index(%arg0: index, %arg1: index) {
181 %0 = math.ipowi %arg0, %arg1 : index