title: Why I can't use virtual register variables in instruction composition?
body: <p>I am trying to utilize instruction composition to make my LLVM IR code more readable, by performing multiple operations at once. I have four virtual register variables that I want to add together and store the result into one <code>%sum</code> variable.</p>
  <p>Here's my code:</p>
  <pre><code>target datalayout = &quot;e-m:e-i64:64-f80:128-n8:16:32:64-S128&quot;
  target triple = &quot;x86_64-unknown-linux-gnu&quot;
  
  define i32 @main() {
      %obj1 = insertvalue {i32, i32} {i32 2, i32 3}, i32 2, 0
      %obj2 = insertvalue {i32, i32} %obj1, i32 7, 1
  
      %1 = extractvalue {i32, i32} %obj1, 0
      %2 = extractvalue {i32, i32} %obj1, 1
      %3 = extractvalue {i32, i32} %obj2, 0
      %4 = extractvalue {i32, i32} %obj2, 1
  
      %sum = add i32
          add (i32 %1, i32 %2),
          add (i32 %3, i32 %4)
  
      ret i32 %sum
  }
  
  </code></pre>
  <p>This code with the instruction composition, to add multiple virtual register variables together, looks syntactically correct to me. However the compiler (or the assembler) displays an error:</p>
  <pre><code> $ llvm-as insertvalue_test.ll -o insertvalue_test.bc
  llvm-as: insertvalue_test.ll:14:18: error: invalid use of function-local name
          add (i32 %1, i32 %2),
                   ^
  </code></pre>
  <p>I do not know what that error means. Even if I replace the virtual register variables with constants, the code compiles and runs fine:</p>
  <pre><code>    %sum = add i32
          add (i32 1, i32 2),
          add (i32 3, i32 4)
  </code></pre>
  <p>Also when I try to just add these two register variables together using one <code>add</code> instruction, it works fine.</p>
  <pre><code>%sum = add i32 %1, %2
  </code></pre>
  <p>However the problem occurs when I attempt to use multiple <code>add</code> instructions in instruction combination to add multiple register variables together.</p>