312 lines · plain
1// RUN: mlir-opt %s -canonicalize="test-convergence" -split-input-file | FileCheck %s2 3///===----------------------------------------------===//4/// Tests of `StepCompareFolder`5///===----------------------------------------------===//6 7 8///===------------------------------------===//9/// Tests of `ugt` (unsigned greater than)10///===------------------------------------===//11 12// CHECK-LABEL: @ugt_constant_3_lhs13// CHECK: %[[CST:.*]] = arith.constant dense<true> : vector<3xi1>14// CHECK: return %[[CST]] : vector<3xi1>15func.func @ugt_constant_3_lhs() -> vector<3xi1> {16 %cst = arith.constant dense<3> : vector<3xindex>17 %0 = vector.step : vector<3xindex>18 // 3 > [0, 1, 2] => [true, true, true] => true for all indices => fold19 %1 = arith.cmpi ugt, %cst, %0 : vector<3xindex>20 return %1 : vector<3xi1>21}22 23// -----24 25// CHECK-LABEL: @negative_ugt_constant_2_lhs26// CHECK: %[[CMP:.*]] = arith.cmpi27// CHECK: return %[[CMP]]28func.func @negative_ugt_constant_2_lhs() -> vector<3xi1> {29 %cst = arith.constant dense<2> : vector<3xindex>30 %0 = vector.step : vector<3xindex>31 // 2 > [0, 1, 2] => [true, true, false] => not same for all indices => don't fold32 %1 = arith.cmpi ugt, %cst, %0 : vector<3xindex>33 return %1 : vector<3xi1>34}35 36// -----37 38// CHECK-LABEL: @ugt_constant_3_rhs39// CHECK: %[[CST:.*]] = arith.constant dense<false> : vector<3xi1>40// CHECK: return %[[CST]] : vector<3xi1>41func.func @ugt_constant_3_rhs() -> vector<3xi1> {42 %cst = arith.constant dense<3> : vector<3xindex>43 %0 = vector.step : vector<3xindex>44 // [0, 1, 2] > 3 => [false, false, false] => false for all indices => fold45 %1 = arith.cmpi ugt, %0, %cst : vector<3xindex>46 return %1 : vector<3xi1>47}48 49// -----50 51// CHECK-LABEL: @ugt_constant_max_rhs52// CHECK: %[[CST:.*]] = arith.constant dense<false> : vector<3xi1>53// CHECK: return %[[CST]] : vector<3xi1>54func.func @ugt_constant_max_rhs() -> vector<3xi1> {55 // The largest i64 possible:56 %cst = arith.constant dense<0x7fffffffffffffff> : vector<3xindex>57 %0 = vector.step : vector<3xindex>58 %1 = arith.cmpi ugt, %0, %cst: vector<3xindex>59 return %1 : vector<3xi1>60}61 62 63// -----64 65// CHECK-LABEL: @ugt_constant_2_rhs66// CHECK: %[[CST:.*]] = arith.constant dense<false> : vector<3xi1>67// CHECK: return %[[CST]] : vector<3xi1>68func.func @ugt_constant_2_rhs() -> vector<3xi1> {69 %cst = arith.constant dense<2> : vector<3xindex>70 %0 = vector.step : vector<3xindex>71 // [0, 1, 2] > 2 => [false, false, false] => false for all indices => fold72 %1 = arith.cmpi ugt, %0, %cst : vector<3xindex>73 return %1 : vector<3xi1>74}75 76// -----77 78// CHECK-LABEL: @negative_ugt_constant_1_rhs79// CHECK: %[[CMP:.*]] = arith.cmpi80// CHECK: return %[[CMP]]81func.func @negative_ugt_constant_1_rhs() -> vector<3xi1> {82 %cst = arith.constant dense<1> : vector<3xindex>83 %0 = vector.step : vector<3xindex>84 // [0, 1, 2] > 1 => [false, false, true] => not same for all indices => don't fold85 %1 = arith.cmpi ugt, %0, %cst: vector<3xindex>86 return %1 : vector<3xi1>87}88 89// -----90 91///===------------------------------------===//92/// Tests of `uge` (unsigned greater than or equal)93///===------------------------------------===//94 95 96// CHECK-LABEL: @uge_constant_2_lhs97// CHECK: %[[CST:.*]] = arith.constant dense<true> : vector<3xi1>98// CHECK: return %[[CST]] : vector<3xi1>99func.func @uge_constant_2_lhs() -> vector<3xi1> {100 %cst = arith.constant dense<2> : vector<3xindex>101 %0 = vector.step : vector<3xindex>102 // 2 >= [0, 1, 2] => [true, true, true] => true for all indices => fold103 %1 = arith.cmpi uge, %cst, %0 : vector<3xindex>104 return %1 : vector<3xi1>105}106 107// -----108 109// CHECK-LABEL: @negative_uge_constant_1_lhs110// CHECK: %[[CMP:.*]] = arith.cmpi111// CHECK: return %[[CMP]]112func.func @negative_uge_constant_1_lhs() -> vector<3xi1> {113 %cst = arith.constant dense<1> : vector<3xindex>114 %0 = vector.step : vector<3xindex>115 // 1 >= [0, 1, 2] => [true, false, false] => not same for all indices => don't fold116 %1 = arith.cmpi uge, %cst, %0 : vector<3xindex>117 return %1 : vector<3xi1>118}119 120// -----121 122// CHECK-LABEL: @uge_constant_3_rhs123// CHECK: %[[CST:.*]] = arith.constant dense<false> : vector<3xi1>124// CHECK: return %[[CST]] : vector<3xi1>125func.func @uge_constant_3_rhs() -> vector<3xi1> {126 %cst = arith.constant dense<3> : vector<3xindex>127 %0 = vector.step : vector<3xindex>128 // [0, 1, 2] >= 3 => [false, false, false] => false for all indices => fold129 %1 = arith.cmpi uge, %0, %cst : vector<3xindex>130 return %1 : vector<3xi1>131}132 133// -----134 135// CHECK-LABEL: @negative_uge_constant_2_rhs136// CHECK: %[[CMP:.*]] = arith.cmpi137// CHECK: return %[[CMP]]138func.func @negative_uge_constant_2_rhs() -> vector<3xi1> {139 %cst = arith.constant dense<2> : vector<3xindex>140 %0 = vector.step : vector<3xindex>141 // [0, 1, 2] >= 2 => [false, false, true] => not same for all indices => don't fold142 %1 = arith.cmpi uge, %0, %cst : vector<3xindex>143 return %1 : vector<3xi1>144}145 146// -----147 148 149///===------------------------------------===//150/// Tests of `ult` (unsigned less than)151///===------------------------------------===//152 153 154// CHECK-LABEL: @ult_constant_2_lhs155// CHECK: %[[CST:.*]] = arith.constant dense<false> : vector<3xi1>156// CHECK: return %[[CST]] : vector<3xi1>157func.func @ult_constant_2_lhs() -> vector<3xi1> {158 %cst = arith.constant dense<2> : vector<3xindex>159 %0 = vector.step : vector<3xindex>160 // 2 < [0, 1, 2] => [false, false, false] => false for all indices => fold161 %1 = arith.cmpi ult, %cst, %0 : vector<3xindex>162 return %1 : vector<3xi1>163}164 165// -----166 167// CHECK-LABEL: @negative_ult_constant_1_lhs168// CHECK: %[[CMP:.*]] = arith.cmpi169// CHECK: return %[[CMP]]170func.func @negative_ult_constant_1_lhs() -> vector<3xi1> {171 %cst = arith.constant dense<1> : vector<3xindex>172 %0 = vector.step : vector<3xindex>173 // 1 < [0, 1, 2] => [false, false, true] => not same for all indices => don't fold174 %1 = arith.cmpi ult, %cst, %0 : vector<3xindex>175 return %1 : vector<3xi1>176}177 178// -----179 180// CHECK-LABEL: @ult_constant_3_rhs181// CHECK: %[[CST:.*]] = arith.constant dense<true> : vector<3xi1>182// CHECK: return %[[CST]] : vector<3xi1>183func.func @ult_constant_3_rhs() -> vector<3xi1> {184 %cst = arith.constant dense<3> : vector<3xindex>185 %0 = vector.step : vector<3xindex>186 // [0, 1, 2] < 3 => [true, true, true] => true for all indices => fold187 %1 = arith.cmpi ult, %0, %cst : vector<3xindex>188 return %1 : vector<3xi1>189}190 191// -----192 193// CHECK-LABEL: @negative_ult_constant_2_rhs194// CHECK: %[[CMP:.*]] = arith.cmpi195// CHECK: return %[[CMP]]196func.func @negative_ult_constant_2_rhs() -> vector<3xi1> {197 %cst = arith.constant dense<2> : vector<3xindex>198 %0 = vector.step : vector<3xindex>199 // [0, 1, 2] < 2 => [true, true, false] => not same for all indices => don't fold200 %1 = arith.cmpi ult, %0, %cst : vector<3xindex>201 return %1 : vector<3xi1>202}203 204// -----205 206///===------------------------------------===//207/// Tests of `ule` (unsigned less than or equal)208///===------------------------------------===//209 210// CHECK-LABEL: @ule_constant_3_lhs211// CHECK: %[[CST:.*]] = arith.constant dense<false> : vector<3xi1>212// CHECK: return %[[CST]] : vector<3xi1>213func.func @ule_constant_3_lhs() -> vector<3xi1> {214 %cst = arith.constant dense<3> : vector<3xindex>215 %0 = vector.step : vector<3xindex>216 %1 = arith.cmpi ule, %cst, %0 : vector<3xindex>217 return %1 : vector<3xi1>218}219 220// -----221 222// CHECK-LABEL: @negative_ule_constant_2_lhs223// CHECK: %[[CMP:.*]] = arith.cmpi224// CHECK: return %[[CMP]]225func.func @negative_ule_constant_2_lhs() -> vector<3xi1> {226 %cst = arith.constant dense<2> : vector<3xindex>227 %0 = vector.step : vector<3xindex>228 %1 = arith.cmpi ule, %cst, %0 : vector<3xindex>229 return %1 : vector<3xi1>230}231 232// -----233 234// CHECK-LABEL: @ule_constant_2_rhs235// CHECK: %[[CST:.*]] = arith.constant dense<true> : vector<3xi1>236// CHECK: return %[[CST]] : vector<3xi1>237func.func @ule_constant_2_rhs() -> vector<3xi1> {238 %cst = arith.constant dense<2> : vector<3xindex>239 %0 = vector.step : vector<3xindex>240 %1 = arith.cmpi ule, %0, %cst : vector<3xindex>241 return %1 : vector<3xi1>242}243 244// -----245 246// CHECK-LABEL: @negative_ule_constant_1_rhs247// CHECK: %[[CMP:.*]] = arith.cmpi248// CHECK: return %[[CMP]]249func.func @negative_ule_constant_1_rhs() -> vector<3xi1> {250 %cst = arith.constant dense<1> : vector<3xindex>251 %0 = vector.step : vector<3xindex>252 %1 = arith.cmpi ule, %0, %cst: vector<3xindex>253 return %1 : vector<3xi1>254}255 256// -----257 258///===------------------------------------===//259/// Tests of `eq` (equal)260///===------------------------------------===//261 262// CHECK-LABEL: @eq_constant_3263// CHECK: %[[CST:.*]] = arith.constant dense<false> : vector<3xi1>264// CHECK: return %[[CST]] : vector<3xi1>265func.func @eq_constant_3() -> vector<3xi1> {266 %cst = arith.constant dense<3> : vector<3xindex>267 %0 = vector.step : vector<3xindex>268 %1 = arith.cmpi eq, %0, %cst: vector<3xindex>269 return %1 : vector<3xi1>270}271 272// -----273 274// CHECK-LABEL: @negative_eq_constant_2275// CHECK: %[[CMP:.*]] = arith.cmpi276// CHECK: return %[[CMP]]277func.func @negative_eq_constant_2() -> vector<3xi1> {278 %cst = arith.constant dense<2> : vector<3xindex>279 %0 = vector.step : vector<3xindex>280 %1 = arith.cmpi eq, %0, %cst: vector<3xindex>281 return %1 : vector<3xi1>282}283 284// -----285 286///===------------------------------------===//287/// Tests of `ne` (not equal)288///===------------------------------------===//289 290// CHECK-LABEL: @ne_constant_3291// CHECK: %[[CST:.*]] = arith.constant dense<true> : vector<3xi1>292// CHECK: return %[[CST]] : vector<3xi1>293func.func @ne_constant_3() -> vector<3xi1> {294 %cst = arith.constant dense<3> : vector<3xindex>295 %0 = vector.step : vector<3xindex>296 %1 = arith.cmpi ne, %0, %cst: vector<3xindex>297 return %1 : vector<3xi1>298}299 300// -----301 302// CHECK-LABEL: @negative_ne_constant_2303// CHECK: %[[CMP:.*]] = arith.cmpi304// CHECK: return %[[CMP]]305func.func @negative_ne_constant_2() -> vector<3xi1> {306 %cst = arith.constant dense<2> : vector<3xindex>307 %0 = vector.step : vector<3xindex>308 %1 = arith.cmpi ne, %0, %cst: vector<3xindex>309 return %1 : vector<3xi1>310}311 312