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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With