antoyo
antoyo

Reputation: 11913

Instruction expected to be numbered

I have a problem with the following LLVM code:

    %0 = load i64* %u
    %1 = load i64* %l
    %2 = icmp sgt i64 %1, %1
    br i1 %2, label %L1, label %L2
L2:
    ret void
    br label %L1
L1:

    %3 = load i64* %l
    %4 = sub i64 %3, 1
    store i64 %4, i64* %i

When running llc, I get the following error:

error: instruction expected to be numbered '%4'
%3 = load i64* %l

But I don't understand why it should be %4 after %2. There are no instruction returning a result between the %2 and %4.

I need to understand this because I am writing an LLVM code generator.

So why is it an error to use %3 here?

Upvotes: 7

Views: 3336

Answers (1)

Oak
Oak

Reputation: 26868

Basic blocks share the same numbering as instructions. Because ret is a terminator, you have an unnamed (and unreachable) basic block starting right after it, so your code is equivalent to:

...
L2:
  ret void
%3:
  br label %L1
L1:
...

And that's why it expects the next unnamed thing to be %4.

Upvotes: 15

Related Questions