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
31 lines
922 B
Fortran
31 lines
922 B
Fortran
! RUN: %flang_fc1 -emit-llvm -o - %s | FileCheck %s
|
|
|
|
! CHECK-LABEL: vector_always
|
|
subroutine vector_always
|
|
integer :: a(10)
|
|
!dir$ vector always
|
|
! CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}
|
|
! CHECK-NOT: !llvm.loop
|
|
! CHECK: br label {{.*}}, !llvm.loop ![[ANNOTATION:.*]]
|
|
do i=1,10
|
|
a(i)=i
|
|
end do
|
|
end subroutine vector_always
|
|
|
|
! CHECK-LABEL: no_vector
|
|
subroutine no_vector
|
|
integer :: a(10)
|
|
!dir$ novector
|
|
! CHECK: br i1 {{.*}}, label {{.*}}, label {{.*}}
|
|
! CHECK-NOT: !llvm.loop
|
|
! CHECK: br label {{.*}}, !llvm.loop ![[ANNOTATION2:.*]]
|
|
do i=1,10
|
|
a(i)=i
|
|
end do
|
|
end subroutine no_vector
|
|
|
|
! CHECK: ![[ANNOTATION]] = distinct !{![[ANNOTATION]], ![[VECTORIZE:.*]]}
|
|
! CHECK: ![[VECTORIZE]] = !{!"llvm.loop.vectorize.enable", i1 true}
|
|
! CHECK: ![[ANNOTATION2]] = distinct !{![[ANNOTATION2]], ![[VECTORIZE2:.*]]}
|
|
! CHECK: ![[VECTORIZE2]] = !{!"llvm.loop.vectorize.enable", i1 false}
|