[LLVMdev] code generation removes duplicated instructions

D S Khudia daya.khudia at gmail.com
Wed Jul 6 16:02:02 PDT 2011

Hi Renato,

I am trying to add a intrinsic call between the similar two instructions
which either I'll remove or convert to nop in codegen.
Does that kind of seem appropriate for the purpose here?


On Wed, Jul 6, 2011 at 11:55 AM, Renato Golin <renato.golin at arm.com> wrote:

> On 6 July 2011 15:57, D S Khudia <daya.khudia at gmail.com> wrote:
> > Since I am inserting a new basic block (contains printf statement and
> > program exit) which is jumped upon based on the result of
> > the comparison, the compiler cannot/shouldnot optimize that away by means
> of
> > DCE or anything else.
> It most certainly can, since the comparison yields always the same
> result. The compiler can replace all that by a simple branch to
> whatever block always executes.
> > In the above example even the operands are not same and I guess compiler
> > cannot be that smart at -O0. I sense something is wrong with the code
> > generation for ARM.
> There're no hard rules stopping any compiler to run DCE or DAG
> combining/elimination or whatever when in O0 or any other level.
> > What other way do you suggest for duplicating since you mentioned I
> > shouldn't rely on duplication the way I am doing it?
> > Thanks a lot. I really appreciate your help.
> What you need is a way to make sure it won't be optimised away,
> possibly even on higher O-levels. You need to add a dependency that
> the compiler cannot see through (or is not smart enough at O0 to do
> so, at least). Because this is a transient change, as a way to debug
> other problems, you're allowed to do ugly stuff.
> For example, you can get a fake offset from an argument, and guarantee
> that this is always zero. Or you can add a random offset internally to
> one of them, and then compare that one is exactly the offset higher
> (or lower) than the other. Or you could pass %a and %b as parameters
> and memcopy them in the caller.
> Anything that would make it difficult for the compiler to see that
> both are the same would do...
> cheers,
> --renato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110706/32b5f926/attachment.html>

More information about the llvm-dev mailing list