where does %a_addr.0 come from?

Hi,

I am studying SSA and some time ago I asked on this list how to see the
phi nodes in the llvm ir output. I learned then to use this command:
opt -mem2reg test.ll -S > test_mem2reg.ll

However, if you look at the output (attached to this message) there is
something I do not understand. At the end of the function @f at line 18,
the function returns the variable %a_addr.0. However, this variable is
never defined or set. The variable %a is. Is "_addr.0" a way to get the
address of a variable? I could not find anything about this in in LLVM
language reference manual.
Where does this variable come from?

thanks,
  Maarten Faddegon

test_mem2reg.ll (1.19 KB)

Hi Maarten,

If you look at the start of basic block 2 (bb2) you'll see the following instruction:
 %a_addr.0 = phi i32 [ 1, %bb ], [ 0, %bb1 ]     ; <i32> [#uses=1]

This is an SSA phi node which assigns a value of either 1 or 0 to %a_addr.0 depending on whether control reached the PHI node from basic block bb, or bb1.

  • Lang.

Elaborating slightly - The mem2reg pass hoists values from memory into registers. It was responsible for adding %a_addr.0 and the PHI node which defines it.

  • Lang.

Hi Maarten,

I am studying SSA and some time ago I asked on this list how to see the
phi nodes in the llvm ir output. I learned then to use this command:
opt -mem2reg test.ll -S> test_mem2reg.ll

However, if you look at the output (attached to this message) there is
something I do not understand. At the end of the function @f at line 18,
the function returns the variable %a_addr.0. However, this variable is
never defined or set.

it is defined here:

   %a_addr.0 = phi i32 [ 1, %bb ], [ 0, %bb1 ] ; <i32> [#uses=1]

Ciao,

Duncan.