[flang-commits] [flang] [flang] [test] add tests for FIRToSCF (PR #176026)

Scott Manley via flang-commits flang-commits at lists.llvm.org
Thu Jan 15 14:54:53 PST 2026


================
@@ -0,0 +1,149 @@
+// Test conversions of fir.do_loop, including cases nested in other regions.
+//
+// RUN: fir-opt %s --fir-to-scf --allow-unregistered-dialect | FileCheck %s
+
+// Test that compiler generated fir.allocas are converted, slightly edited from:
+// subroutine loop(a)
+//   integer :: a(4)
+//   a = 1
+// end
+
+// CHECK-LABEL: func.func @implied_do
+// CHECK:       [[SUB:%[0-9]+]] = arith.subi %c4{{.*}}, %c1{{.*}} : index
+// CHECK-NEXT:  [[ADD:%[0-9]+]] = arith.addi [[SUB]], %c1{{.*}} : index
+// CHECK-NEXT:  [[DIV:%[0-9]+]] = arith.divsi [[ADD]], %c1{{.*}} : index
+// CHECK:       scf.for %arg1 = %c0{{.*}} to [[DIV]] step %c1{{.*}} {
+
+func.func @implied_do(%arg0: !fir.ref<!fir.array<4xi32>> {fir.bindc_name = "a"}) {
+  %c1 = arith.constant 1 : index
+  %c1_i32 = arith.constant 1 : i32
+  %c4 = arith.constant 4 : index
+  %0 = fir.dummy_scope : !fir.dscope
+  %1 = fir.shape %c4 : (index) -> !fir.shape<1>
+  %2 = fir.declare %arg0(%1) dummy_scope %0 {uniq_name = "_QFloopEa"} : (!fir.ref<!fir.array<4xi32>>, !fir.shape<1>, !fir.dscope) -> !fir.ref<!fir.array<4xi32>>
+  fir.do_loop %arg1 = %c1 to %c4 step %c1 unordered {
+    %3 = fir.array_coor %2(%1) %arg1 : (!fir.ref<!fir.array<4xi32>>, !fir.shape<1>, index) -> !fir.ref<i32>
+    fir.store %c1_i32 to %3 : !fir.ref<i32>
+  }
+  return
+}
+
+// Test fir.do_loop that is not directly inside a func.func but nested inside
+// another region.
+//
+// subroutine implied_do_in_acc_serial(a)
+//   integer :: a(4)
+//   !$acc serial
+//   a = 1
+//   !$acc end serial
+// end
+
+// CHECK-LABEL: @implied_do_in_acc_serial
+// CHECK-NOT:   fir.do_loop
----------------
rscottmanley wrote:

Same here - check for scf

https://github.com/llvm/llvm-project/pull/176026


More information about the flang-commits mailing list