65 lines · plain
1// Regression test for https://github.com/llvm/llvm-project/issues/1201902// Verify that hlfir.forall lowering does not try hoisting mask evaluation3// that refer to the forall index inside nested regions only.4// RUN: fir-opt %s --lower-hlfir-ordered-assignments | FileCheck %s5 6func.func @issue120190(%array: !fir.ref<!fir.array<100xf32>>, %cdt: i1) {7 %cst = arith.constant 0.000000e+00 : f328 %c1 = arith.constant 1 : i649 %c50 = arith.constant 50 : i6410 %c100 = arith.constant 100 : i6411 hlfir.forall lb {12 hlfir.yield %c1 : i6413 } ub {14 hlfir.yield %c100 : i6415 } (%forall_index: i64) {16 hlfir.forall_mask {17 %mask = fir.if %cdt -> i1 {18 // Reference to %forall_index is not directly in19 // hlfir.forall_mask region, but is nested.20 %res = arith.cmpi slt, %forall_index, %c50 : i6421 fir.result %res : i122 } else {23 %res = arith.cmpi sgt, %forall_index, %c50 : i6424 fir.result %res : i125 }26 hlfir.yield %mask : i127 } do {28 hlfir.region_assign {29 hlfir.yield %cst : f3230 } to {31 %6 = hlfir.designate %array (%forall_index) : (!fir.ref<!fir.array<100xf32>>, i64) -> !fir.ref<f32>32 hlfir.yield %6 : !fir.ref<f32>33 }34 }35 }36 return37}38 39// CHECK-LABEL: func.func @issue120190(40// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.array<100xf32>>,41// CHECK-SAME: %[[VAL_1:.*]]: i1) {42// CHECK: %[[VAL_2:.*]] = arith.constant 0.000000e+00 : f3243// CHECK: %[[VAL_3:.*]] = arith.constant 1 : i6444// CHECK: %[[VAL_4:.*]] = arith.constant 50 : i6445// CHECK: %[[VAL_5:.*]] = arith.constant 100 : i6446// CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_3]] : (i64) -> index47// CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_5]] : (i64) -> index48// CHECK: %[[VAL_8:.*]] = arith.constant 1 : index49// CHECK: fir.do_loop %[[VAL_9:.*]] = %[[VAL_6]] to %[[VAL_7]] step %[[VAL_8]] {50// CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (index) -> i6451// CHECK: %[[VAL_11:.*]] = fir.if %[[VAL_1]] -> (i1) {52// CHECK: %[[VAL_12:.*]] = arith.cmpi slt, %[[VAL_10]], %[[VAL_4]] : i6453// CHECK: fir.result %[[VAL_12]] : i154// CHECK: } else {55// CHECK: %[[VAL_13:.*]] = arith.cmpi sgt, %[[VAL_10]], %[[VAL_4]] : i6456// CHECK: fir.result %[[VAL_13]] : i157// CHECK: }58// CHECK: fir.if %[[VAL_11]] {59// CHECK: %[[VAL_14:.*]] = hlfir.designate %[[VAL_0]] (%[[VAL_10]]) : (!fir.ref<!fir.array<100xf32>>, i64) -> !fir.ref<f32>60// CHECK: hlfir.assign %[[VAL_2]] to %[[VAL_14]] : f32, !fir.ref<f32>61// CHECK: }62// CHECK: }63// CHECK: return64// CHECK: }65