Use Of Instruction Is Not An Instruction

I’ve seen one post online about the “use of instruction is not an instruction” error, and I’m running into a similar issue, but without a good reason.

I’m using moe (Llvm) to write LLVM to build a compiler and my issue basically comes down to 3 lines:

let pointer = L.build_alloca float_t ("reg") builder in      L.dump_value(pointer);
  let test = L.build_store (L.const_float float_t 32.3) pointer builder      in L.dump_value(test);
   let loaded = L.build_load pointer ("reg") builder  in L.     dump_value(loaded);

what I’m doing here is basically using alloc to get some space in memory, then storing the value of 32.3 to that space, and trying to load it back into the place I allocated in memory .

LLVM wise, it looks pretty good, as, after the dump_module, output, I get something like this:

align 8  %reg = alloca double, align 8 
store double 3.230000e+01, double* %reg, align 8
%x13 = load double, double* %reg, align 8

which should be exactly what I want – I even tested this out by writing up a similar C program and it does something very similar to this in LLVM.

However, when I run my program I get the following error:

Use of instruction is not an instruction!
 %x13 = load double, double* %reg, align 8

which really doesn’t seem to make sense. I check out the error a bit more, and it seems like it’s caused by a few lines in the LLVM source code:

     if (Instruction *Used = dyn_cast<Instruction>(U.getUser()))
       Assert(Used->getParent() != nullptr,
              "Instruction referencing"
              " instruction not embedded in a basic block!",
              &I, Used);
     else {
       CheckFailed("Use of instruction is not an instruction!", U);
       return;
     }
   }

which seem to imply it happens if the instructions don’t have a parent, but I’m not sure why that would be the case.

Any help here would be very much appreciated!

Let me expand a bit the sample:

  // Check that all uses of the instruction, if they are instructions
  // themselves, actually have parent basic blocks.  If the use is not an
  // instruction, it is an error!
  for (Use &U : I.uses()) {
    if (Instruction *Used = dyn_cast<Instruction>(U.getUser()))
      Assert(Used->getParent() != nullptr,
             "Instruction referencing"
             " instruction not embedded in a basic block!",
             &I, Used);
    else {
      CheckFailed("Use of instruction is not an instruction!", U);
      return;
    }
  }

So this is looking at all the uses of %x13 and if one of them is not an instruction it’ll fail. The parent check is in the other side of the branch and does not seem relevant to what you see.
How are you using you loaded value?
Something you can try is to add after CheckFailed("Use of instruction is not an instruction!", U); a line with U.getUser().dump();.

1 Like

Ah thank you! Yes, this was exactly the issues – I wasn’t correctly using %x13 that was returned – fixing this solved my problem!