Antonin Reitz via llvm-dev
2019-Jul-23 19:11 UTC
[llvm-dev] Accessing global variables arrays result in inlined getelementptrs
Hello, Using LLVM+clang to do some static analysis, I face some issues due to the fact that when manipulating arrays that are global variables, IR getelementptr instructions seem to be somehow inlined. For example: int a[256]; int main() { a[0] = 1; } gives as a result the following IR code (with clang+llvm 8, without any flag). @a = common dso_local global [256 x i32] zeroinitializer, align 16 ; Function Attrs: noinline nounwind optnone sspstrong uwtable define dso_local i32 @main() #0 { store i32 1, i32* getelementptr inbounds ([256 x i32], [256 x i32]* @a, i64 0, i64 0), align 16 ret i32 0 } Hence two questions. - What is the main reason behind this behavior? - Is there a way to disable it (ideally while preserving optimisations disabled)? Thank you in advance, Antonin Reitz
Michael Kruse via llvm-dev
2019-Jul-23 19:38 UTC
[llvm-dev] Accessing global variables arrays result in inlined getelementptrs
Am Di., 23. Juli 2019 um 15:11 Uhr schrieb Antonin Reitz via llvm-dev <llvm-dev at lists.llvm.org>:> Hence two questions. > - What is the main reason behind this behavior?The getelementptr has all constant argument, meaning it itself becomes an GetElementPtrConstantExpr. ConstantExprs (in contrast to instructions) are inlined by the IR emitter.> - Is there a way to disable it (ideally while preserving optimisations > disabled)?Not that I know of. Michael
Antonin Reitz via llvm-dev
2019-Jul-24 22:01 UTC
[llvm-dev] Accessing global variables arrays result in inlined getelementptrs
On 7/23/19 3:38 PM, Michael Kruse wrote:> The getelementptr has all constant argument, meaning it itself becomes > an GetElementPtrConstantExpr. ConstantExprs (in contrast to > instructions) are inlined by the IR emitter. >> - Is there a way to disable it (ideally while preserving optimisations >> disabled)?Is it something that would be relatively easy to change with a local patch for LLVM without introducing a lot of modifications? (only disabling GetElementPtrConstantExprs inlining) This is really something that would help having simpler static analysis, even if additional analysis of the code can be used as a (quite ugly) workaround. Thank you very much, Antonin