#pragma clang loop pipeline(disable) is ignored when other transformation pragmas exist
For example, llvm.loop.pipeline.disable is not generated by the following code. (https://godbolt.org/z/vaxhKfG6b)
void f(double *a, int n) {
#pragma clang loop unroll(enable) pipeline(disable)
for (int i=0; i<n; i++)
a[i]++;
}
llvm.loop.pipeline.disable metadata is not generated for the loop:
!36 = distinct !{!36, !30, !37, !38, !39}
!37 = !DILocation(line: 4, column: 9, scope: !23)
!38 = !{!"llvm.loop.mustprogress"}
!39 = !{!"llvm.loop.unroll.enable"}
It is implemented in such a way that when an earlier transformation is enabled, a metadata for a later one will be generated only if it is enabled.
In fact, rewriting pipeline(disable) to pipeline_initiation_interval(1) (this means pipeline is enabled) in the above code produces the following metadata:
!36 = distinct !{!36, !30, !37, !38, !39, !40}
!37 = !DILocation(line: 4, column: 9, scope: !23)
!38 = !{!"llvm.loop.mustprogress"}
!39 = !{!"llvm.loop.unroll.enable"}
!40 = !{!"llvm.loop.unroll.followup_all", !41}
!41 = distinct !{!41, !30, !37, !38, !42, !43}
!42 = !{!"llvm.loop.unroll.disable"}
!43 = !{!"llvm.loop.pipeline.initiationinterval", i32 1}
This can be resolved by turning on a flag that indicates that a transformation exists (HasUserTransforms) even in the case of disable in the following code:
https://github.com/llvm/llvm-project/blob/f4efa067435c8137718c907bf0de2b891b76552d/clang/lib/CodeGen/CGLoopInfo.cpp#L49-L56
Will this change break the intent of the original code or have any side effects?
It is similar for other more commonly used transformations, such as vectorization and unrolling, but for those, they can be consequently disabled in other ways. vectorize(disable) is interpreted as vectorize.width==1, so HasUserTransforms is turned on. The metadata for unroll(disable) is generated by the first transformation (createFullUnrollMetadata), so HasUserTransforms is not necessary to be on.
CC @AaronBallman @erichkeane
I would like to do this. Could you assign it to me?
I would like to do this. Could you assign it to me?
We don't assign issues until there is a PR and we check that it is moving in the right direction.
In this case, no one with the right knowledge has confirmed this issue, so I would be hesitant to encourage someone to take this on.
I’ve looked into and fixed parts of this area (loop metadata) before, so I have some knowledge and would like to comment. I think the expected metadata for the program in the description is something like below:
!36 = distinct !{!36, !37, !38, !39, ... }
!37 = !{!"llvm.loop.mustprogress"}
!38 = !{!"llvm.loop.unroll.enable"}
!39 = !{!"llvm.loop.unroll.followup_all", !37, !40, !41}
!40 = !{!"llvm.loop.unroll.disable"}
!41 = !{!"llvm.loop.pipeline.disable", i1 true}
But !41 is not correctly emitted for some reason. At a glance, LoopInfo::createPipeliningMetadata doesn't seem to be called as expected. Perhaps the right approach is to adjust the condition so that this method is invoked appropriately.