[llvm-dev] Use case for function unswitching.

Nema, Ashutosh via llvm-dev llvm-dev at lists.llvm.org
Fri Jun 7 02:31:33 PDT 2019


Hi Raghesh,

Partial inline has support for function unswitching, you can explore it.

Note: It does not handle the functions marked with no-inline attribute.

Regards,
Ashutosh

From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of raghesh via llvm-dev
Sent: Friday, June 7, 2019 2:03 PM
To: llvm-dev at lists.llvm.org
Subject: [llvm-dev] Use case for function unswitching.

[CAUTION: External Email]
Dear All,

It would be great if anyone help me out in finding a use case similar to the following example.

__attribute__((noinline))
int f (int p) {
    if (p == 10) {      // if-1
        return 0;
    }
    // Some statements here.
    return 2;
}

int g(int p) {
    return f(p);
}

Here, I would like to see if the compiler does a transformation, where the if statement (if-1) in the body of the function 'f' is removed from 'f' and pushed to the caller 'g' as follows. Please note that I have forced not to inline 'f'.

int f (int p) {
     // Some statements here.
    return 2;
}

int g(int p) {
    if (p == 10) {      // if-1
        return 0;
    }
    return f(p);
}

This is a simple example that I used just to demonstrate the optimization (we may call it as function switching). If you know about any other use cases, where similar transformation happens, please let me know. When I generated the llvm IR (with -O3) such a transformation was not observed.

Regards,
--
Raghesh Aloor
PhD Scholar
PACE Lab, Dept. of CSE, IIT Madras
http://www.cse.iitm.ac.in/~raghesh/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190607/810aded3/attachment.html>


More information about the llvm-dev mailing list