Flang currently adds loop metadata to a conditional branch in the loop preheader, while clang adds it to the loop latch's branch instruction. Langref says: > Currently, loop metadata is implemented as metadata attached to the branch instruction in the loop latch block. > > https://llvm.org/docs/LangRef.html#llvm-loop I misread langref a couple times, but I think this is the appropriate branch op for the LoopAnnotationAttr. In a couple examples I found that the metadata was lost entirely during canonicalization. This patch makes the codegen look more like clang's and the annotations persist through codegen. * current clang: https://godbolt.org/z/8WhbcrnG3 * current flang: https://godbolt.org/z/TrPboqqcn
58 lines
1.8 KiB
Fortran
58 lines
1.8 KiB
Fortran
! RUN: %flang_fc1 -emit-llvm -o - %s | FileCheck %s
|
|
|
|
! CHECK-LABEL: unroll_dir
|
|
subroutine unroll_dir
|
|
integer :: a(10)
|
|
!dir$ unroll
|
|
! CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}
|
|
! CHECK-NOT: !llvm.loop
|
|
! CHECK: br label {{.*}}, !llvm.loop ![[UNROLL_ENABLE_FULL_ANNO:.*]]
|
|
do i=1,10
|
|
a(i)=i
|
|
end do
|
|
end subroutine unroll_dir
|
|
|
|
! CHECK-LABEL: unroll_dir_0
|
|
subroutine unroll_dir_0
|
|
integer :: a(10)
|
|
!dir$ unroll 0
|
|
! CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}
|
|
! CHECK-NOT: !llvm.loop
|
|
! CHECK: br label {{.*}}, !llvm.loop ![[UNROLL_DISABLE_ANNO:.*]]
|
|
do i=1,10
|
|
a(i)=i
|
|
end do
|
|
end subroutine unroll_dir_0
|
|
|
|
! CHECK-LABEL: unroll_dir_1
|
|
subroutine unroll_dir_1
|
|
integer :: a(10)
|
|
!dir$ unroll 1
|
|
! CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}
|
|
! CHECK-NOT: !llvm.loop
|
|
! CHECK: br label {{.*}}, !llvm.loop ![[UNROLL_DISABLE_ANNO]]
|
|
do i=1,10
|
|
a(i)=i
|
|
end do
|
|
end subroutine unroll_dir_1
|
|
|
|
! CHECK-LABEL: unroll_dir_2
|
|
subroutine unroll_dir_2
|
|
integer :: a(10)
|
|
!dir$ unroll 2
|
|
! CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}
|
|
! CHECK-NOT: !llvm.loop
|
|
! CHECK: br label {{.*}}, !llvm.loop ![[UNROLL_ENABLE_COUNT_2:.*]]
|
|
do i=1,10
|
|
a(i)=i
|
|
end do
|
|
end subroutine unroll_dir_2
|
|
|
|
! CHECK: ![[UNROLL_ENABLE_FULL_ANNO]] = distinct !{![[UNROLL_ENABLE_FULL_ANNO]], ![[UNROLL_ENABLE:.*]], ![[UNROLL_FULL:.*]]}
|
|
! CHECK: ![[UNROLL_ENABLE:.*]] = !{!"llvm.loop.unroll.enable"}
|
|
! CHECK: ![[UNROLL_FULL:.*]] = !{!"llvm.loop.unroll.full"}
|
|
! CHECK: ![[UNROLL_DISABLE_ANNO]] = distinct !{![[UNROLL_DISABLE_ANNO]], ![[UNROLL_DISABLE:.*]]}
|
|
! CHECK: ![[UNROLL_DISABLE]] = !{!"llvm.loop.unroll.disable"}
|
|
! CHECK: ![[UNROLL_ENABLE_COUNT_2]] = distinct !{![[UNROLL_ENABLE_COUNT_2]], ![[UNROLL_ENABLE]], ![[UNROLL_COUNT_2:.*]]}
|
|
! CHECK: ![[UNROLL_COUNT_2]] = !{!"llvm.loop.unroll.count", i32 2}
|