|
| 1 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -fno-clangir-direct-lowering -emit-mlir %s -o %t.mlir |
| 2 | +// RUN: FileCheck --input-file=%t.mlir %s |
| 3 | + |
| 4 | +int a[101], b[101]; |
| 5 | + |
| 6 | +void constantLoopBound() { |
| 7 | + for (int i = 0; i < 100; ++i) |
| 8 | + a[i] = 3; |
| 9 | +} |
| 10 | +// CHECK-LABEL: func.func @_Z17constantLoopBoundv() { |
| 11 | +// CHECK: %[[C0:.*]] = arith.constant 0 : i32 |
| 12 | +// CHECK: %[[C100:.*]] = arith.constant 100 : i32 |
| 13 | +// CHECK: %[[C1:.*]] = arith.constant 1 : i32 |
| 14 | +// CHECK: scf.for %[[I:.*]] = %[[C0]] to %[[C100]] step %[[C1]] : i32 { |
| 15 | +// CHECK: %[[C3:.*]] = arith.constant 3 : i32 |
| 16 | +// CHECK: %[[BASE:.*]] = memref.get_global @a : memref<101xi32> |
| 17 | +// CHECK: %[[C0_i32:.*]] = arith.constant 0 : i32 |
| 18 | +// CHECK: %[[IV:.*]] = arith.addi %[[I]], %[[C0_i32]] : i32 |
| 19 | +// CHECK: %[[INDEX:.*]] = arith.index_cast %[[IV]] : i32 to index |
| 20 | +// CHECK: memref.store %[[C3]], %[[BASE]][%[[INDEX]]] : memref<101xi32> |
| 21 | +// CHECK: } |
| 22 | + |
| 23 | +void constantLoopBound_LE() { |
| 24 | + for (int i = 0; i <= 100; ++i) |
| 25 | + a[i] = 3; |
| 26 | +} |
| 27 | +// CHECK-LABEL: func.func @_Z20constantLoopBound_LEv() { |
| 28 | +// CHECK: %[[C0:.*]] = arith.constant 0 : i32 |
| 29 | +// CHECK: %[[C100:.*]] = arith.constant 100 : i32 |
| 30 | +// CHECK: %[[C1:.*]] = arith.constant 1 : i32 |
| 31 | +// CHECK: %[[C101:.*]] = arith.addi %c100_i32, %c1_i32 : i32 |
| 32 | +// CHECK: %[[C1_STEP:.*]] = arith.constant 1 : i32 |
| 33 | +// CHECK: scf.for %[[I:.*]] = %[[C0]] to %[[C101]] step %[[C1_STEP]] : i32 { |
| 34 | +// CHECK: %[[C3:.*]] = arith.constant 3 : i32 |
| 35 | +// CHECK: %[[BASE:.*]] = memref.get_global @a : memref<101xi32> |
| 36 | +// CHECK: %[[C0_i32:.*]] = arith.constant 0 : i32 |
| 37 | +// CHECK: %[[IV:.*]] = arith.addi %[[I]], %[[C0_i32]] : i32 |
| 38 | +// CHECK: %[[INDEX:.*]] = arith.index_cast %[[IV]] : i32 to index |
| 39 | +// CHECK: memref.store %[[C3]], %[[BASE]][%[[INDEX]]] : memref<101xi32> |
| 40 | +// CHECK: } |
| 41 | + |
| 42 | +void variableLoopBound(int l, int u) { |
| 43 | + for (int i = l; i < u; ++i) |
| 44 | + a[i] = 3; |
| 45 | +} |
| 46 | +// CHECK-LABEL: func.func @_Z17variableLoopBoundii |
| 47 | +// CHECK: memref.store %arg0, %alloca[] : memref<i32> |
| 48 | +// CHECK: memref.store %arg1, %alloca_0[] : memref<i32> |
| 49 | +// CHECK: %[[LOWER:.*]] = memref.load %alloca[] : memref<i32> |
| 50 | +// CHECK: %[[UPPER:.*]] = memref.load %alloca_0[] : memref<i32> |
| 51 | +// CHECK: %[[C1:.*]] = arith.constant 1 : i32 |
| 52 | +// CHECK: scf.for %[[I:.*]] = %[[LOWER]] to %[[UPPER]] step %[[C1]] : i32 { |
| 53 | +// CHECK: %[[C3:.*]] = arith.constant 3 : i32 |
| 54 | +// CHECK: %[[BASE:.*]] = memref.get_global @a : memref<101xi32> |
| 55 | +// CHECK: %[[C0:.*]] = arith.constant 0 : i32 |
| 56 | +// CHECK: %[[IV:.*]] = arith.addi %[[I]], %[[C0]] : i32 |
| 57 | +// CHECK: %[[INDEX:.*]] = arith.index_cast %[[IV]] : i32 to index |
| 58 | +// CHECK: memref.store %[[C3]], %[[BASE]][%[[INDEX]]] : memref<101xi32> |
| 59 | +// CHECK: } |
| 60 | + |
| 61 | +void ariableLoopBound_LE(int l, int u) { |
| 62 | + for (int i = l; i <= u; i+=4) |
| 63 | + a[i] = 3; |
| 64 | +} |
| 65 | +// CHECK-LABEL: func.func @_Z19ariableLoopBound_LEii |
| 66 | +// CHECK: memref.store %arg0, %alloca[] : memref<i32> |
| 67 | +// CHECK: memref.store %arg1, %alloca_0[] : memref<i32> |
| 68 | +// CHECK: %[[LOWER:.*]] = memref.load %alloca[] : memref<i32> |
| 69 | +// CHECK: %[[UPPER_DEC_1:.*]] = memref.load %alloca_0[] : memref<i32> |
| 70 | +// CHECK: %[[C1:.*]] = arith.constant 1 : i32 |
| 71 | +// CHECK: %[[UPPER:.*]] = arith.addi %[[UPPER_DEC_1]], %[[C1]] : i32 |
| 72 | +// CHECK: %[[C4:.*]] = arith.constant 4 : i32 |
| 73 | +// CHECK: scf.for %[[I:.*]] = %[[LOWER]] to %[[UPPER]] step %[[C4]] : i32 { |
| 74 | +// CHECK: %[[C3:.*]] = arith.constant 3 : i32 |
| 75 | +// CHECK: %[[BASE:.*]] = memref.get_global @a : memref<101xi32> |
| 76 | +// CHECK: %[[C0:.*]] = arith.constant 0 : i32 |
| 77 | +// CHECK: %[[IV:.*]] = arith.addi %[[I]], %[[C0]] : i32 |
| 78 | +// CHECK: %[[INDEX:.*]] = arith.index_cast %[[IV]] : i32 to index |
| 79 | +// CHECK: memref.store %[[C3]], %[[BASE]][%[[INDEX]]] : memref<101xi32> |
| 80 | +// CHECK: } |
| 81 | + |
| 82 | +void incArray() { |
| 83 | + for (int i = 0; i < 100; ++i) |
| 84 | + a[i] += b[i]; |
| 85 | +} |
| 86 | +// CHECK-LABEL: func.func @_Z8incArrayv() { |
| 87 | +// CHECK: %[[C0:.*]] = arith.constant 0 : i32 |
| 88 | +// CHECK: %[[C100:.*]] = arith.constant 100 : i32 |
| 89 | +// CHECK: %[[C1:.*]] = arith.constant 1 : i32 |
| 90 | +// CHECK: scf.for %[[I:.*]] = %[[C0]] to %[[C100]] step %[[C1]] : i32 { |
| 91 | +// CHECK: %[[B:.*]] = memref.get_global @b : memref<101xi32> |
| 92 | +// CHECK: %[[C0_2:.*]] = arith.constant 0 : i32 |
| 93 | +// CHECK: %[[IV2:.*]] = arith.addi %[[I]], %[[C0_2]] : i32 |
| 94 | +// CHECK: %[[INDEX_2:.*]] = arith.index_cast %[[IV2]] : i32 to index |
| 95 | +// CHECK: %[[B_VALUE:.*]] = memref.load %[[B]][%[[INDEX_2]]] : memref<101xi32> |
| 96 | +// CHECK: %[[A:.*]] = memref.get_global @a : memref<101xi32> |
| 97 | +// CHECK: %[[C0_1:.*]] = arith.constant 0 : i32 |
| 98 | +// CHECK: %[[IV1:.*]] = arith.addi %[[I]], %[[C0_1]] : i32 |
| 99 | +// CHECK: %[[INDEX_1:.*]] = arith.index_cast %[[IV1]] : i32 to index |
| 100 | +// CHECK: %[[A_VALUE:.*]] = memref.load %[[A]][%[[INDEX_1]]] : memref<101xi32> |
| 101 | +// CHECK: %[[SUM:.*]] = arith.addi %[[A_VALUE]], %[[B_VALUE]] : i32 |
| 102 | +// CHECK: memref.store %[[SUM]], %[[A]][%[[INDEX_1]]] : memref<101xi32> |
| 103 | +// CHECK: } |
0 commit comments