[llvm-dev] Disabling optimizations in clang/llvm for specified regions in code

Noor, Abdul Rafae via llvm-dev llvm-dev at lists.llvm.org
Mon Oct 4 15:24:18 PDT 2021


Hello,
I wanted to inquire if there is a way within LLVM/Clang to limit (function-level) optimizations to certain contiguous regions within the function. E.g.

void foo(int* A, int n1, int n2){

         // Enable optimizations above this loop
         ...
         // (#pragma clang loop nolicm?)
         for(int i = 0; i < n1; ++i){
                 for(int j=0; j< n2; j++){
                          int i_offset = (n2*i); // Do not Hoist to outside current loop
                          int net_offset = i_offset + j;
                          A[net_offset] = ...;

                 }
         }
         // Enable optimizations below this loop

         ...
}

In the above case, would it be possible to disable Loop Invariant Code motion just for that loop nest in the function foo, but enable it to be used elsewhere in the function? We would like to disable certain passes like LICM for our use-case (We’ve defined markers inside the functions specifying the start and end of certain regions and we want to limit certain optimizations as we will be extracting those code regions later on).

The clang pragma at https://bcain-llvm.readthedocs.io/projects/clang/en/latest/LanguageExtensions/#id20 acts at a per function level. Similarly the loop optimizations pragmas https://clang.llvm.org/docs/LanguageExtensions.html#id30 only cover some of the loop specific metadata’s available in LLVM (For example, I wasn’t able to find a way to add ‘llvm.licm.disable’ to loops at the source level).

Thank you,
Abdul Rafae Noor
Grad Student,
University of Illinois, Urbana Champaign

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20211004/6e849303/attachment-0001.html>


More information about the llvm-dev mailing list