[flang-commits] [flang] [flang] Implement !DIR$ IVDEP directive (PR #133728)

Kiran Kumar T P via flang-commits flang-commits at lists.llvm.org
Wed May 14 04:09:16 PDT 2025


kiranktp wrote:

Hi @JDPailleux, Thanks for the patch.
for ivdep pragma, clang generates below metadata:
!8 = !{!"llvm.loop.vectorize.ivdep.enable", i1 true}
!9 = !{!"llvm.loop.vectorize.enable", i1 true}

but flang will generate below metadata:
CHECK: ![[VECTORIZE]] = !{!"llvm.loop.vectorize.enable", i1 true}
! CHECK: ![[PARALLEL_ACCESSES]] = !{!"llvm.loop.parallel_accesses", [[DISTRINCT]]}

IMO, the behavior of clang and flang should match.

In AMD downstream compiler we have below support for different directives
[Apologies, I had promised for an RFC, but i couldn't get that done in time]

1. !DIR$ VECTOR
	This directive must generate below metadata:
	!18 = !{!"llvm.loop.vectorize.enable", i1 true}
        This works as a hint to the optimizer.
	But the optimizer will anyway check for profitability of vectorization and then decide if vectorization should be done or not.  This behavior is similar to "#pragma clang loop vectorize(enable)" for clang

2. !DIR$ NOVECTOR
	This directive must generate below metadata:
	!28 = !{!"llvm.loop.vectorize.width", i1 true}
	This will disable vectorizing the loop across all optimization levels
        This behavior is similar to "#pragma clang loop vectorize(disable)"

3. !DIR$ IVDEP
	This directive must generate below metedata:
	!28 = !{!"llvm.loop.vectorize.enable", i1 true}
	!29 = !{ !"llvm.loop.vectorize.ivdep.enable", i1 1 }
	!30 = !{ !30, !29, !28 }
       This behavior is similar to "#pragma clang loop ivdep(enable)"

4. !DIR$ VECTOR ALWAYS
	This directive must generate below metedata:
	!28 = !{!"llvm.loop.vectorize.enable", i1 true}
	!29 = !{!"llvm.loop.parallel_accesses", !26}
	This will vectorize the loop irrespective of the profitability of the vectorization.
	This directive should be used with caution
NOTE: As I am aware, this was the behavior for "!DIR$ SIMD" directive. IMO "!DIR$ SIMD" will not be supported in llvm-flang. So we can have this behavior under "!DIR$ VECTOR ALWAYS"

Let me know your opinion. 


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


More information about the flang-commits mailing list