How to prevent duplication of function calls?

Hello,

Is it possible to prevent duplication of call sites for specific functions (while still maintaining –O3 optimization level)? For example, the following C code:

This came up a long time ago, but I'm not sure what the resolution was:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-October/026312.html

There's also TID::isNotDuplicable:
http://llvm.org/docs/doxygen/html/classllvm_1_1TargetInstrDesc.html#ab05b074805f22503828b5b625d437f3a

I don't know enough about LLVM's backend to say if you can get that on
an intrinsic.

Reid

Thanks Reid. It looks like the first thread didn't really get anywhere. The author most likely just modified the offending passes to respect the barriers (this is my guess based on what I read in that thread).

By the time back-end starts, it's too late, since the front end does some of the duplications.

For the record, I probably will end up doing the following:
- Modifying passes that duplicate the calls not to do so.
- Marking all barrier calls with a new global variable.
- Assert that no duplication happened (i.e. there are no two barriers that access the same global marker). If that happens, tell the user to turn down optimizations until the assert failure goes away :(.

This is a maintenance problem but probably still easier than writing generic re-merging pass.

Dmitry

Dmitry,
We never were able to get a resolution for this issue. What we have done is made modifications to LLVM to disable duplication of barrier in specific optimization passes. Once we fully integrate with 2.9 we plan on attempting to merge some of those changes back in to LLVM.

Micah

Hi,

I wanted to start the 'barrier duplication' discussion again. Last time around Eli proposed to add a new attribute "executebarrier" which will prevent the duplication of barriers. I am considering implementing this feature. Anyone opposes this approach, or had already implemented it ?

Thanks,
Nadav