[LLVMdev] Question about compilation result - taking address of input array member

Eli Bendersky eliben at google.com
Thu Feb 14 08:17:44 PST 2013


On Wed, Feb 13, 2013 at 9:21 PM, Lang Hames <lhames at gmail.com> wrote:
> Hi Eli,
>
> I'm not sure if this is the answer you're looking for, but the alloca, store
> and load can be removed by the mem2reg pass, which isn't run by codegen
> prepare in llc. If you invoke clang with -O1 or above it will run mem2reg,
> producing IR that contains only the gep, and that produces the assembly
> you're looking for:
>
> $ clang -cc1 -emit-llvm -O1 takeaddr.c
> $ cat takeaddr.ll
>
> define i32* @bar(i32* %table) nounwind readnone {
> entry:
>   %arrayidx = getelementptr inbounds i32* %table, i64 2
>   ret i32* %arrayidx
> }
>
> $ llc takeaddr.ll
> $ cat takeaddr.s
> <snip>
> _bar:                                   ## @bar
> ## BB#0:                                ## %entry
>         leaq    8(%rdi), %rax
>         ret

Hi Lang,

Thanks for taking the time to reply. This makes sense, since my
question disregards the division in responsibility between opt and llc
in running IR passes. A colleague pointed this out to me after I sent
the question, but I was waiting for additional input and then forgot
to say that the mystery is solved.

Eli



More information about the llvm-dev mailing list