|
| 1 | +// ========================================================================== // |
| 2 | +// Copyright (c) 2022 - 2025 NVIDIA Corporation & Affiliates. // |
| 3 | +// All rights reserved. // |
| 4 | +// // |
| 5 | +// This source code and the accompanying materials are made available under // |
| 6 | +// the terms of the Apache License 2.0 which accompanies this distribution. // |
| 7 | +// ========================================================================== // |
| 8 | + |
| 9 | +// RUN: cudaq-opt -cc-loop-normalize %s | FileCheck %s |
| 10 | + |
| 11 | +module { |
| 12 | + func.func @test_positive_boundaries() { |
| 13 | + %c0_i64 = arith.constant 0 : i64 |
| 14 | + %c1_i64 = arith.constant 1 : i64 |
| 15 | + %0 = quake.alloca !quake.veq<0> |
| 16 | + %1 = cc.loop while ((%arg0 = %c1_i64) -> (i64)) { |
| 17 | + %2 = arith.cmpi ult, %arg0, %c0_i64 : i64 |
| 18 | + cc.condition %2(%arg0 : i64) |
| 19 | + } do { |
| 20 | + ^bb0(%arg0: i64): |
| 21 | + %2 = arith.subi %arg0, %c1_i64 : i64 |
| 22 | + %3 = quake.extract_ref %0[%2] : (!quake.veq<0>, i64) -> !quake.ref |
| 23 | + quake.x %3 : (!quake.ref) -> () |
| 24 | + cc.continue %arg0 : i64 |
| 25 | + } step { |
| 26 | + ^bb0(%arg0: i64): |
| 27 | + %2 = arith.addi %arg0, %c1_i64 : i64 |
| 28 | + cc.continue %2 : i64 |
| 29 | + } |
| 30 | + return |
| 31 | + } |
| 32 | + |
| 33 | +// CHECK-LABEL: func.func @test_positive_boundaries() { |
| 34 | +// CHECK: %[[VAL_0:.*]] = arith.constant 0 : i64 |
| 35 | +// CHECK: %[[VAL_1:.*]] = arith.constant 1 : i64 |
| 36 | +// CHECK: %[[VAL_2:.*]] = quake.alloca !quake.veq<0> |
| 37 | +// CHECK: %[[VAL_3:.*]] = cc.loop while ((%arg0 = %[[VAL_0]]) -> (i64)) { |
| 38 | +// CHECK: %[[VAL_4:.*]] = arith.cmpi ne, %arg0, %[[VAL_0]] : i64 |
| 39 | +// CHECK: cc.condition %[[VAL_4]](%arg0 : i64) |
| 40 | +// CHECK: } do { |
| 41 | +// CHECK: ^bb0(%arg0: i64): |
| 42 | +// CHECK: %[[VAL_4:.*]] = quake.extract_ref %[[VAL_2]][%arg0] : (!quake.veq<0>, i64) -> !quake.ref |
| 43 | +// CHECK: quake.x %[[VAL_4]] : (!quake.ref) -> () |
| 44 | +// CHECK: cc.continue %arg0 : i64 |
| 45 | +// CHECK: } step { |
| 46 | +// CHECK: ^bb0(%arg0: i64): |
| 47 | +// CHECK: %[[VAL_4:.*]] = arith.addi %arg0, %[[VAL_1]] : i64 |
| 48 | +// CHECK: cc.continue %[[VAL_4]] : i64 |
| 49 | +// CHECK: } {normalized} |
| 50 | +// CHECK: return |
| 51 | +// CHECK: } |
| 52 | + |
| 53 | + func.func @test_negative_boundaries() { |
| 54 | + %c-1_i32 = arith.constant -1 : i32 |
| 55 | + %c1_i32 = arith.constant 1 : i32 |
| 56 | + %c0_i32 = arith.constant 0 : i32 |
| 57 | + %0 = quake.alloca !quake.veq<0> |
| 58 | + %1 = cc.loop while ((%arg0 = %c0_i32) -> (i32)) { |
| 59 | + %2 = arith.cmpi slt, %arg0, %c-1_i32 : i32 |
| 60 | + cc.condition %2(%arg0 : i32) |
| 61 | + } do { |
| 62 | + ^bb0(%arg0: i32): |
| 63 | + %2 = cc.cast signed %arg0 : (i32) -> i64 |
| 64 | + %3 = quake.extract_ref %0[%2] : (!quake.veq<0>, i64) -> !quake.ref |
| 65 | + quake.x %3 : (!quake.ref) -> () |
| 66 | + cc.continue %arg0 : i32 |
| 67 | + } step { |
| 68 | + ^bb0(%arg0: i32): |
| 69 | + %2 = arith.addi %arg0, %c1_i32 : i32 |
| 70 | + cc.continue %2 : i32 |
| 71 | + } |
| 72 | + return |
| 73 | + } |
| 74 | + |
| 75 | +// CHECK-LABEL: func.func @test_negative_boundaries() { |
| 76 | +// CHECK: %[[VAL_0:.*]] = arith.constant 0 : i32 |
| 77 | +// CHECK: %[[VAL_1:.*]] = arith.constant 1 : i32 |
| 78 | +// CHECK: %[[VAL_2:.*]] = quake.alloca !quake.veq<0> |
| 79 | +// CHECK: %[[VAL_3:.*]] = cc.loop while ((%arg0 = %[[VAL_0]]) -> (i32)) { |
| 80 | +// CHECK: %[[VAL_4:.*]] = arith.cmpi ne, %arg0, %[[VAL_0]] : i32 |
| 81 | +// CHECK: cc.condition %[[VAL_4]](%arg0 : i32) |
| 82 | +// CHECK: } do { |
| 83 | +// CHECK: ^bb0(%arg0: i32): |
| 84 | +// CHECK: %[[VAL_4:.*]] = cc.cast signed %arg0 : (i32) -> i64 |
| 85 | +// CHECK: %[[VAL_5:.*]] = quake.extract_ref %[[VAL_2]][%[[VAL_4]]] : (!quake.veq<0>, i64) -> !quake.ref |
| 86 | +// CHECK: quake.x %[[VAL_5]] : (!quake.ref) -> () |
| 87 | +// CHECK: cc.continue %arg0 : i32 |
| 88 | +// CHECK: } step { |
| 89 | +// CHECK: ^bb0(%arg0: i32): |
| 90 | +// CHECK: %[[VAL_4:.*]] = arith.addi %arg0, %[[VAL_1]] : i32 |
| 91 | +// CHECK: cc.continue %[[VAL_4]] : i32 |
| 92 | +// CHECK: } {normalized} |
| 93 | +// CHECK: return |
| 94 | +// CHECK: } |
| 95 | +} |
0 commit comments