このような LLVM IR コードがあります。
%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
..............
arrayidx1が割り当てられている行では、すべて問題ありませんが、 OldFuncCounter7の場合、LLVM コンパイラは「関数ローカル名の無効な使用」と言って文句を言います。これは、私が使用している %8 が原因です。定数に置き換えると、正常に動作します。私の質問は、 %8 がarrayidx1 では正常に機能するのに、 OldFuncCounter7では機能しない理由です。ここで何が起こっているのですか?
このエラーが発生する基本ブロック全体を以下に示します
%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