Need a clue to improve the optimization of some C code

Hi

I have some inline function C code, that llvm could be optimizing better.
Since I am new to this, I wonder if someone could give me a few pointers, how to approach this in LLVM.

Should I try to change the IR code -somehow- to get the code generator to generate better code, or should I rather go to the code generator and try to add an optimization pass ?

Thanks for any feedback.

Ciao
   Nat!

P.S. In case someone is interested, here is the assembler code and the IR that produced it.

Relevant LLVM generated x86_64 assembler portion with -Os

You'll need to prove a bit more information to get any useful response. Questions:
1) What's you're use case? Are you using clang to compile C code? Are you manually generating LLVM IR?
2) Are you tracking ToT? If you're not, you should be.

Depending on your use case, you might find this document useful:
http://llvm.org/docs/Frontend/PerformanceTips.html

Hi Philip

first thanks for your response,

You'll need to prove a bit more information to get any useful response. Questions:
1) What's you're use case? Are you using clang to compile C code? Are you manually generating LLVM IR?

yes the "inline function C code" will be compiled by clang.

2) Are you tracking ToT? If you're not, you should be.

Currently the git repo doesn't build for me (libLLVMR600CodeGen fails). Admittedly my IR output is from an older version - 3.6.

Depending on your use case, you might find this document useful:
Performance Tips for Frontend Authors — LLVM 18.0.0git documentation

Maybe yes, if it would be sensible to rewrite the IR, which I am wondering, if that is a good/useful idea ? I don't know.

I basically need to get LLVM to emit

Updating my previous mail...

Updating my previous mail...

2) Are you tracking ToT? If you're not, you should be.

Currently the git repo doesn't build for me (libLLVMR600CodeGen fails). Admittedly my IR output is from an older version - 3.6.

Ok, I got the trunk to build now. Luckily indeed the emitted assembler code has improved (a lot). Yet the produced code is still a bit larger than what it would be if written by hand. Since I try to optimize for size, my question how it would be smart to tackle this within LLVM remains.

File a bug report with a small IR reproducer of the problematic code sequence. Ideally, send a patch to llvm-commits.

Also, make sure you're using -Oz if you care about size above all.