https://llvm.org/bugs/show_bug.cgi?id=31096
Bug ID: 31096 Summary: Multi-level pointers not disambiguated, even with strict aliasing Product: libraries Version: trunk Hardware: PC OS: All Status: NEW Severity: normal Priority: P Component: Global Analyses Assignee: unassignedb...@nondot.org Reporter: dber...@dberlin.org CC: llvm-bugs@lists.llvm.org Classification: Unclassified The following simple example: int *p; int foo(int argc, char **argv) { int result; *p = 2; if (argc) *p = 2; result = *p; return result; } Does not get optimized by GVN (or NewGVN). It's trivial friend: int foo(int argc, char **argv, int *p) { int result; *p = 2; if (argc) *p = 2; result = *p; return result; } Does get optimized by NewGVN with a patch i have. The difference is that the global object turns into an i32 ** that we do a load from, so the llvm IR looks like this: @p = common global i32* null, align 8 ; Function Attrs: norecurse nounwind ssp uwtable define i32 @foo(i32, i8** nocapture readnone) #0 { %3 = load i32*, i32** @p, align 8, !tbaa !2 store i32 2, i32* %3, align 4, !tbaa !6 %4 = icmp eq i32 %0, 0 br i1 %4, label %7, label %5 ; <label>:5 ; preds = %2 %6 = load i32*, i32** @p, align 8, !tbaa !2 store i32 2, i32* %6, align 4, !tbaa !6 br label %7 ; <label>:7 ; preds = %2, %5 %8 = load i32*, i32** @p, align 8, !tbaa !2 %9 = load i32, i32* %8, align 4, !tbaa !6 ret i32 %9 } !0 = !{i32 1, !"PIC Level", i32 2} !1 = !{!"Apple LLVM version 8.0.0 (clang-800.0.42.1)"} !2 = !{!3, !3, i64 0} !3 = !{!"any pointer", !4, i64 0} !4 = !{!"omnipotent char", !5, i64 0} !5 = !{!"Simple C/C++ TBAA"} !6 = !{!7, !7, i64 0} !7 = !{!"int", !4, i64 0} Note that in this two level version, we believe the stores to i32* can affect an i32**. At the "llvm level" this is correct (IE there are no real types, aso we can't say anything) , however, with strict aliasing, and the original code, it's not possible. In fact, at least for basic types, with strict aliasing, it's not possible for a pointer of level n to affect a pointer of level n+1 (IE a store to an int * can't ever alias an int **, only the reverse) , but we haven't taught LLVM that. (I suspect, btw, the above can be reproduced with multi-level pointers in general) Not sure where we should fix this, suggestions welcome. -- You are receiving this mail because: You are on the CC list for the bug.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs