James Courtier-Dutton via llvm-dev
2020-May-31 08:49 UTC
[llvm-dev] Question about Constant expressions
Hi, Why is the getelementptr part of the call instruction, instead of being a separate instruction in the LLVM IR ? The LLVM IR Builder adds it as a separate instruction, but it is rolled into one call instruction in the .bc output. I am just curious as to why it is done this way. #include <stdint.h> #include <stdio.h> int test21(void); int test21(void) { printf("Hello1\n"); return 0; } define dso_local i32 @test21() #0 { %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0)) ret i32 0 }
Johannes Doerfert via llvm-dev
2020-May-31 15:55 UTC
[llvm-dev] Question about Constant expressions
Hi James, Like other constant expressions, e.g., i32 0, this GEP constant expression are "shown" inlined. Constants are unique and exist everywhere. I guess the most "important' use case I can think of is to use such GEPs as part of other constant expressions, e.g., initializers of constant globals. Cheers, Johannes On 5/31/20 3:49 AM, James Courtier-Dutton via llvm-dev wrote:> Hi, > > Why is the getelementptr part of the call instruction, instead of > being a separate instruction in the LLVM IR ? > The LLVM IR Builder adds it as a separate instruction, but it is > rolled into one call instruction in the .bc output. > I am just curious as to why it is done this way. > > #include <stdint.h> > #include <stdio.h> > int test21(void); > int test21(void) { > printf("Hello1\n"); > return 0; > } > > define dso_local i32 @test21() #0 { > %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x > i8], [8 x i8]* @.str, i64 0, i64 0)) > ret i32 0 > } > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200531/71275c9f/attachment.html>
James Courtier-Dutton via llvm-dev
2020-Jun-13 15:29 UTC
[llvm-dev] Question about Constant expressions
Hi, What I meant was, why is it not represented by something like this instead: define dso_local i32 @test21() #0 { %1 = i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0) %2 = call i32 (i8*, ...) @printf(%1) ret i32 0 } instead of: define dso_local i32 @test21() #0 { %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0)) ret i32 0 } Some code I am writing would be a lot simpler if the first case was used. On Sun, 31 May 2020 at 16:56, Johannes Doerfert <johannesdoerfert at gmail.com> wrote:> > Hi James, > > > Like other constant expressions, e.g., i32 0, this GEP constant > > expression are "shown" inlined. Constants are unique and exist > > everywhere. I guess the most "important' use case I can think > > of is to use such GEPs as part of other constant expressions, > > e.g., initializers of constant globals. > > > Cheers, > > Johannes > > > On 5/31/20 3:49 AM, James Courtier-Dutton via llvm-dev wrote: > > Hi, > > Why is the getelementptr part of the call instruction, instead of > being a separate instruction in the LLVM IR ? > The LLVM IR Builder adds it as a separate instruction, but it is > rolled into one call instruction in the .bc output. > I am just curious as to why it is done this way. > > #include <stdint.h> > #include <stdio.h> > int test21(void); > int test21(void) { > printf("Hello1\n"); > return 0; > } > > define dso_local i32 @test21() #0 { > %1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x > i8], [8 x i8]* @.str, i64 0, i64 0)) > ret i32 0 > } > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev