brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 0bf4b02 Raw
67 lines · plain
1// RUN: mlir-opt %s -convert-cf-to-llvm -split-input-file | FileCheck %s2 3// Unstructured control flow is converted, but the enclosing op is not4// converted.5 6// CHECK-LABEL: func.func @single_case(7//  CHECK-SAME:     %[[val:.*]]: i32, %[[idx:.*]]: index) -> index {8//       CHECK:   %[[cast0:.*]] = builtin.unrealized_conversion_cast %[[idx]] : index to i649//       CHECK:   llvm.switch %[[val]] : i32, ^[[bb1:.*]](%[[cast0]] : i64) [10//       CHECK:   ]11//       CHECK: ^[[bb1]](%[[arg0:.*]]: i64):12//       CHECK:   %[[cast1:.*]] = builtin.unrealized_conversion_cast %[[arg0]] : i64 to index13//       CHECK:   return %[[cast1]] : index14//       CHECK: }15func.func @single_case(%val: i32, %idx: index) -> index {16  cf.switch %val : i32, [17    default: ^bb1(%idx : index)18  ]19^bb1(%arg0: index):20  return %arg0 : index21}22 23// -----24 25// func.func and func.return types match. No unrealized_conversion_cast is26// needed.27 28// CHECK-LABEL: func.func @single_case_type_match(29//  CHECK-SAME:     %[[val:.*]]: i32, %[[i:.*]]: i64) -> i64 {30//       CHECK:   llvm.switch %[[val]] : i32, ^[[bb1:.*]](%[[i]] : i64) [31//       CHECK:   ]32//       CHECK: ^[[bb1]](%[[arg0:.*]]: i64):33//       CHECK:   return %[[arg0]] : i6434//       CHECK: }35func.func @single_case_type_match(%val: i32, %i: i64) -> i64 {36  cf.switch %val : i32, [37    default: ^bb1(%i : i64)38  ]39^bb1(%arg0: i64):40  return %arg0 : i6441}42 43// -----44 45//   CHECK-LABEL: func.func @multi_case46// CHECK-COUNT-2:   unrealized_conversion_cast {{.*}} : index to i6447//         CHECK:   llvm.switch %{{.*}} : i32, ^{{.*}}(%{{.*}} : i64) [48//         CHECK:     12: ^{{.*}}(%{{.*}} : i64),49//         CHECK:     13: ^{{.*}}(%{{.*}} : i64),50//         CHECK:     14: ^{{.*}}(%{{.*}} : i64)51//         CHECK:   ]52func.func @multi_case(%val: i32, %idx1: index, %idx2: index, %i: i64) -> index {53  cf.switch %val : i32, [54    default: ^bb1(%idx1 : index),55    12: ^bb2(%idx2 : index),56    13: ^bb1(%idx1 : index),57    14: ^bb3(%i : i64)58  ]59^bb1(%arg0: index):60  return %arg0 : index61^bb2(%arg1: index):62  return %arg1 : index63^bb3(%arg2: i64):64  %cast = arith.index_cast %arg2 : i64 to index65  return %cast : index66}67