alloca

Hello,

is the alloca instruction itself valid input for stores instructions ( and maybe some others?). In all realistic examples I encountered it as input only to getelementptr instruction.

Sure. Loads and stores.

int foo(int i){
return i;
}

$ clang alloca.c -S -emit-llvm
$ cat alloca.ll
; ModuleID = ‘alloca.c’
target datalayout = “e-m:e-i64:64-f80:128-n8:16:32:64-S128”
target triple = “x86_64-pc-linux-gnu”

; Function Attrs: nounwind uwtable
define i32 @foo(i32 %i) #0 {
%1 = alloca i32, align 4
store i32 %i, i32* %1, align 4
%2 = load i32, i32* %1, align 4
ret i32 %2
}

attributes #0 = { nounwind uwtable “disable-tail-calls”=“false” “less-precise-fpmad”=“false” “no-frame-pointer-elim”=“true” “no-frame-pointer-elim-non-leaf” “no-infs-fp-math”=“false” “no-nans-fp-math”=“false” “stack-protector-buffer-size”=“8” “target-cpu”=“x86-64” “target-features”=“+fxsr,+mmx,+sse,+sse2” “unsafe-fp-math”=“false” “use-soft-float”=“false” }

!llvm.ident = !{!0}

!0 = !{!“clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)”}

It is. Bruce has already covered the address part, but if you're
interested in the value being stored you'd typically see it for code
that stored a local address somewhere (maybe to a global). In
semi-idiomatic C:

int *var;
void foo() {
   int local;
   var = &local; // Produces a store of the "local" alloca to @var
   do_something_with_var();
}

Cheers.

Tim.