brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.9 KiB · cdd5c98 Raw
146 lines · plain
1! Test loop variables increment2! RUN: bbc -emit-fir -hlfir=false -o - %s | FileCheck %s3 4module test_loop_var5  implicit none6  integer, pointer:: i_pointer7  integer, allocatable :: i_allocatable8  real, pointer :: x_pointer9  real, allocatable :: x_allocatable10contains11! CHECK-LABEL: func @_QMtest_loop_varPtest_pointer12  subroutine test_pointer()13    do i_pointer=1,1014    enddo15! CHECK:         %[[VAL_0:.*]] = fir.address_of(@_QMtest_loop_varEi_pointer) : !fir.ref<!fir.box<!fir.ptr<i32>>>16! CHECK:         %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<i32>>>17! CHECK:         %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.ptr<i32>>) -> !fir.ptr<i32>18! CHECK:         %[[VAL_9:.*]] = fir.do_loop{{.*}}iter_args(%[[IV:.*]] = {{.*}})19! CHECK:           fir.store %[[IV]] to %[[VAL_2]] : !fir.ptr<i32>20! CHECK:         }21! CHECK:         fir.store %[[VAL_9]] to %[[VAL_2]] : !fir.ptr<i32>22  end subroutine23 24! CHECK-LABEL: func @_QMtest_loop_varPtest_allocatable25  subroutine test_allocatable()26    do i_allocatable=1,1027    enddo28! CHECK:         %[[VAL_0:.*]] = fir.address_of(@_QMtest_loop_varEi_allocatable) : !fir.ref<!fir.box<!fir.heap<i32>>>29! CHECK:         %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.heap<i32>>>30! CHECK:         %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.heap<i32>>) -> !fir.heap<i32>31! CHECK:         %[[VAL_9:.*]] = fir.do_loop{{.*}}iter_args(%[[IV:.*]] = {{.*}})32! CHECK:           fir.store %[[IV]] to %[[VAL_2]] : !fir.heap<i32>33! CHECK:         }34! CHECK:         fir.store %[[VAL_9]] to %[[VAL_2]] : !fir.heap<i32>35  end subroutine36 37! CHECK-LABEL: func @_QMtest_loop_varPtest_real_pointer38  subroutine test_real_pointer()39    do x_pointer=1,1040    enddo41! CHECK:         %[[VAL_0:.*]] = fir.alloca index42! CHECK:         %[[VAL_1:.*]] = fir.address_of(@_QMtest_loop_varEx_pointer) : !fir.ref<!fir.box<!fir.ptr<f32>>>43! CHECK:         %[[VAL_2:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.ptr<f32>>>44! CHECK:         %[[VAL_3:.*]] = fir.box_addr %[[VAL_2]] : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>45! CHECK:         %[[VAL_4:.*]] = arith.constant 1 : i3246! CHECK:         %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i32) -> f3247! CHECK:         %[[VAL_8:.*]] = arith.constant 1.000000e+00 : f3248 49! CHECK:         fir.store %[[VAL_5]] to %[[VAL_3]] : !fir.ptr<f32>50! CHECK:         br ^bb151! CHECK:       ^bb1:52! CHECK:         cond_br %{{.*}}, ^bb2, ^bb353! CHECK:       ^bb2:54! CHECK:         %[[VAL_19:.*]] = fir.load %[[VAL_3]] : !fir.ptr<f32>55! CHECK:         %[[VAL_20:.*]] = arith.constant 1.000000e+00 : f3256! CHECK:         %[[VAL_21:.*]] = arith.addf %[[VAL_19]], %[[VAL_20]] {{.*}}: f3257! CHECK:         fir.store %[[VAL_21]] to %[[VAL_3]] : !fir.ptr<f32>58! CHECK:         br ^bb159! CHECK:       ^bb3:60! CHECK:         return61  end subroutine62 63! CHECK-LABEL: func @_QMtest_loop_varPtest_real_allocatable64  subroutine test_real_allocatable()65    do x_allocatable=1,1066    enddo67! CHECK:         %[[VAL_0:.*]] = fir.alloca index68! CHECK:         %[[VAL_1:.*]] = fir.address_of(@_QMtest_loop_varEx_allocatable) : !fir.ref<!fir.box<!fir.heap<f32>>>69! CHECK:         %[[VAL_2:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.heap<f32>>>70! CHECK:         %[[VAL_3:.*]] = fir.box_addr %[[VAL_2]] : (!fir.box<!fir.heap<f32>>) -> !fir.heap<f32>71! CHECK:         %[[VAL_4:.*]] = arith.constant 1 : i3272! CHECK:         %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (i32) -> f3273! CHECK:         %[[VAL_8:.*]] = arith.constant 1.000000e+00 : f3274 75! CHECK:         fir.store %[[VAL_5]] to %[[VAL_3]] : !fir.heap<f32>76! CHECK:         br ^bb177! CHECK:       ^bb1:78! CHECK:         cond_br %{{.*}}, ^bb2, ^bb379! CHECK:       ^bb2:80! CHECK:         %[[VAL_19:.*]] = fir.load %[[VAL_3]] : !fir.heap<f32>81! CHECK:         %[[VAL_20:.*]] = arith.constant 1.000000e+00 : f3282! CHECK:         %[[VAL_21:.*]] = arith.addf %[[VAL_19]], %[[VAL_20]] {{.*}}: f3283! CHECK:         fir.store %[[VAL_21]] to %[[VAL_3]] : !fir.heap<f32>84! CHECK:         br ^bb185! CHECK:       ^bb3:86! CHECK:         return87  end subroutine88 89  ! CHECK-LABEL: func @_QMtest_loop_varPtest_pointer_unstructured_loop()90  subroutine test_pointer_unstructured_loop()91    do i_pointer=1,1092      if (i_pointer .gt. 5) exit93    enddo94! CHECK:         %[[VAL_1:.*]] = fir.address_of(@_QMtest_loop_varEi_pointer) : !fir.ref<!fir.box<!fir.ptr<i32>>>95! CHECK:         %[[VAL_2:.*]] = fir.load %[[VAL_1]] : !fir.ref<!fir.box<!fir.ptr<i32>>>96! CHECK:         %[[VAL_3:.*]] = fir.box_addr %[[VAL_2]] : (!fir.box<!fir.ptr<i32>>) -> !fir.ptr<i32>97! CHECK:         %[[VAL_4:.*]] = arith.constant 1 : i3298! CHECK:         %[[VAL_6:.*]] = arith.constant 1 : i3299! CHECK:         fir.store %[[VAL_4]] to %[[VAL_3]] : !fir.ptr<i32>100! CHECK:         br ^bb1101! CHECK:       ^bb1:102! CHECK:         cond_br %{{.*}}, ^bb2, ^bb5103! CHECK:       ^bb2:104! CHECK:         cond_br %{{.*}}, ^bb3, ^bb4105! CHECK:       ^bb3:106! CHECK:         br ^bb5107! CHECK:       ^bb4:108! CHECK:         %[[VAL_20:.*]] = fir.load %[[VAL_3]] : !fir.ptr<i32>109! CHECK:         %[[VAL_21:.*]] = arith.constant 1 : i32110! CHECK:         %[[VAL_22:.*]] = arith.addi %[[VAL_20]], %[[VAL_21]] overflow<nsw> : i32111! CHECK:         fir.store %[[VAL_22]] to %[[VAL_3]] : !fir.ptr<i32>112! CHECK:         br ^bb1113! CHECK:       ^bb5:114! CHECK:         return115! CHECK:       }116  end subroutine117 118end module119 120  use test_loop_var121  implicit none122  integer, target :: i_target = -1123  real, target :: x_target = -1.124  i_pointer => i_target125  allocate(i_allocatable)126  i_allocatable = -1127  x_pointer => x_target128  allocate(x_allocatable)129  x_allocatable = -1.130 131  call test_pointer()132  call test_allocatable()133  call test_real_pointer()134  call test_real_allocatable()135  ! Expect 11 everywhere136  print *, i_target137  print *, i_allocatable138  print *, x_target139  print *, x_allocatable140 141  call test_pointer_unstructured_loop()142  call test_allocatable_unstructured_loop()143  ! Expect 6 everywhere144  print *, i_target145end146