Reputation: 21665
I have an LLVM IR code that looks something like this.
%8 = load i64* @tid, align 8
%arrayidx1 = getelementptr inbounds [16 x i32]* @h,
i32 0, i64 %8 ;<-- %8 works fine here
..............
%OldFuncCounter7 = load i64* getelementptr inbounds ([16 x i64]*
@EdgeProfCounters, i64 0, i64 %8) ;<-- error here, %8 not allowed
..............
In the line where arrayidx1 is assigned, everything is fine, but for OldFuncCounter7, the LLVM compiler complains by saying "invalid use of function-local name". It is due to the %8 I am using. If i replace it with a constant, it works fine. So my question is why is that %8 works fine with arrayidx1, but not with OldFuncCounter7. What is going on here?
The whole basic block where this error occurs is shown below
%8 = load i64* @tid, align 8
%arrayidx1 = getelementptr inbounds [16 x i32]* @h, i32 0, i64 %8
store volatile i32 3, i32* %arrayidx1, align 4
%9 = load volatile i32* getelementptr inbounds ([16 x i32]* @h, i32 0, i64 0), align 4
%call2 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([10 x i8]* @.str, i32 0, i32 0), i32 %9)
%10 = load i64* @tid, align 8
store volatile i64 %10, i64* %clock, align 8
%call3 = call i32 @getpid() nounwind
%call4 = call i64 @pthread_self() nounwind readnone
%11 = load volatile i64* %clock, align 8
%call5 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([21 x i8]* @.str1, i32 0, i32 0), i32 %call3, i64 %call4, i64 %11)
store i64 0, i64* %oi, align 8
; Error here due to %8
%OldFuncCounter7 = load i64* getelementptr inbounds ([16 x i64]* @EdgeProfCounters, i64 0, i64 %8)
;
%NewFuncCounter8 = add i64 %OldFuncCounter7, 13
store volatile i64 %NewFuncCounter8, i64* getelementptr inbounds ([16 x i64]* @EdgeProfCounters, i64 0, i64 0)
br label %for.cond6
Upvotes: 4
Views: 2318
Reputation: 26898
You are using %8
from within a constant expression, but it is not a constant. You need to fix your code to perform the getelementptr
instruction outside of a constant expression:
%temp = getelementptr inbounds [16 x i64]* @EdgeProfCounters, i64 0, i64 %8
%OldFuncCounter7 = load i64* %temp
Upvotes: 4