About "error: instruction expected to be numbered"

Hi,

  store i8* %7, i8** %6, align 8, !dbg !96
  %8 = load i8*, i8** %6, align 8, !dbg !98
  %9 = call %struct._IO_FILE* @fopen(i8* %8, i8* getelementptr
inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0)), !dbg !99

I changed the above machine generated IR code into the following to
get rid off %6 and %8.

  %9 = call %struct._IO_FILE* @fopen(i8* %7, i8* getelementptr
inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0)), !dbg !99

When I run llvm-as on it, I got the following.

llvm-as: main.exe.ll:52:3: error: instruction expected to be numbered '%8'

Must the register number be ordered and be without gaps between
instructions? Is there a way to allow more flexible register
numbering?

The things in the IR dump with the % prefix are "values" (see Value in Value.h). Values may have names, but don't have to. When a value has a name, it's printed after the %, so a value with a name "foo" will be printed as %foo. Values with names have no restrictions on ordering relative to other values.
Values that don't have names will be printed with numbers (e.g. %9), but these numbers are not related to names, and they will not become names. The numbers are created pretty much out of thin air by the code that prints the IR. The flip side is that when the IR is parsed, the numbers corresponding to the anonymous values must be sequential, so that you cannot have "%5 = ..." followed by "%7 = ...". As you noticed, this makes manual editing of the IR somewhat tricky. The easiest thing to do is to make sure that all values have names, and to do that you can do "opt -S -instnamer < input.ll > output.ll", and all anonymous values in input.ll will get names tmp1, tmp2, etc.

-Krzysztof