Dear LLVM Developers, My name is Artem Vopilov, I am a student at TU Darmstadt. I am writing to you to ask about Alias Analysis. I am using llvm to analyze alias between variables in programs. I am using Alias Analysis implemented in llvm with command "opt -analyze -aa-eval -print-all-alias-modref-info" and for printing sets of alias "opt -analyze -aa-eval -print-alias-sets". I execute these commands on the small test program I attached to this email. If you take a look at it, it will be obvious, that variables "ptra" and "ptrb" alias. However, the results of Alias Analysis do not indicate, that these variable alias. I would like to ask you, if it is possible to change the source code of Alias Analysis, so that it will show that "ptra" and "ptrb" variables from the test program alias. I am looking forward to hearing from you and hope, that you can help me solve my problem. Respectfully yours, Artem Vopilov -------------- next part -------------- A non-text attachment was scrubbed... Name: Test.c Type: text/x-c Size: 493 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181212/adddf750/attachment.bin>
The variables ptra and ptrb don't actually alias. A simple way to think of aliasing is to to say two l-values alias if assigning into one changes the other. In your program changing the value of ptra does not change the value of ptrb. What you do have is two pointers that point to the same l-value. The aliasing analysis will show that variable a (which is address taken) is aliased to a shadow of type int. Any indirections through ptra or ptrb will use that same shadow. This is how clang and llvm get the aliasing correct. This is a common mistake when learning about aliasing. People often think the pointer should alias the object. It's really the shadow (i.e. a pointer indirection) that aliases the object. In fact you can never have two variables ever alasing each other. Regards -- Sean Perry Compiler Development IBM Canada Lab (905)-413-6031 (tie 313-6031), fax (905)-413-4839 From: "Артём Вопилов via llvm-dev" <llvm-dev at lists.llvm.org> To: llvm-admin at lists.llvm.org, llvm-dev at lists.llvm.org, mailman at lists.llvm.org, bugs-admin at lists.llvm.org Date: 12/12/18 11:54 AM Subject: [llvm-dev] LLVM Alias Analysis Sent by: "llvm-dev" <llvm-dev-bounces at lists.llvm.org> Dear LLVM Developers, My name is Artem Vopilov, I am a student at TU Darmstadt. I am writing to you to ask about Alias Analysis. I am using llvm to analyze alias between variables in programs. I am using Alias Analysis implemented in llvm with command "opt -analyze -aa-eval -print-all-alias-modref-info" and for printing sets of alias "opt -analyze -aa-eval -print-alias-sets". I execute these commands on the small test program I attached to this email. If you take a look at it, it will be obvious, that variables "ptra" and "ptrb" alias. However, the results of Alias Analysis do not indicate, that these variable alias. I would like to ask you, if it is possible to change the source code of Alias Analysis, so that it will show that "ptra" and "ptrb" variables from the test program alias. I am looking forward to hearing from you and hope, that you can help me solve my problem. Respectfully yours, Artem Vopilov [attachment "Test.c" deleted by Sean Perry/Toronto/IBM] _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org http://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/20181212/d614e61b/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: graycol.gif Type: image/gif Size: 105 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181212/d614e61b/attachment.gif>
To Artem: Next time It will be great if you also attach the IR code you feed into your opt analyze command, the output result, and point out that why you think ptra and ptrb don’t alias. And basically I agree what Sean stated in this thread: a pointer is just a variable containing memory address, so pointer itself will never alias with other pointers, but the ‘pointee’ will alias with other memory addresses. Bekket> On Dec 12, 2018, at 10:36 AM, Sean Perry via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > The variables ptra and ptrb don't actually alias. A simple way to think of aliasing is to to say two l-values alias if assigning into one changes the other. In your program changing the value of ptra does not change the value of ptrb. What you do have is two pointers that point to the same l-value. The aliasing analysis will show that variable a (which is address taken) is aliased to a shadow of type int. Any indirections through ptra or ptrb will use that same shadow. This is how clang and llvm get the aliasing correct. > > This is a common mistake when learning about aliasing. People often think the pointer should alias the object. It's really the shadow (i.e. a pointer indirection) that aliases the object. In fact you can never have two variables ever alasing each other. > > Regards > -- > Sean Perry > Compiler Development > IBM Canada Lab > (905)-413-6031 <tel:(905)-413-6031> (tie 313-6031 <tel:313-6031>), fax (905)-413-4839 <tel:(905)-413-4839> > > > <graycol.gif>"Артём Вопилов via llvm-dev" ---12/12/2018 11:54:24 AM---Dear LLVM Developers, My name is Artem Vopilov, I am a student at TU Darmstadt. I am writing to you > > From: "Артём Вопилов via llvm-dev" <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> > To: llvm-admin at lists.llvm.org <mailto:llvm-admin at lists.llvm.org>, llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>, mailman at lists.llvm.org <mailto:mailman at lists.llvm.org>, bugs-admin at lists.llvm.org <mailto:bugs-admin at lists.llvm.org> > Date: 12/12/18 11:54 AM > Subject: [llvm-dev] LLVM Alias Analysis > Sent by: "llvm-dev" <llvm-dev-bounces at lists.llvm.org <mailto:llvm-dev-bounces at lists.llvm.org>> > > > > > Dear LLVM Developers, > > My name is Artem Vopilov, I am a student at TU Darmstadt. I am writing to you to ask about Alias Analysis. > > I am using llvm to analyze alias between variables in programs. I am using Alias Analysis implemented in llvm with command "opt -analyze -aa-eval -print-all-alias-modref-info" and for printing sets of alias "opt -analyze -aa-eval -print-alias-sets". > > I execute these commands on the small test program I attached to this email. > If you take a look at it, it will be obvious, that variables "ptra" and "ptrb" alias. However, the results of Alias Analysis do not indicate, that these variable alias. I would like to ask you, if it is possible to change the source code of Alias Analysis, so that it will show that "ptra" and "ptrb" variables from the test program alias. > > I am looking forward to hearing from you and hope, that you can help me solve my problem. > > Respectfully yours, > Artem Vopilov > [attachment "Test.c" deleted by Sean Perry/Toronto/IBM] > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev> > > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://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/20181212/537ed763/attachment.html>
Doerfert, Johannes Rudolf via llvm-dev
2018-Dec-12 23:20 UTC
[llvm-dev] LLVM Alias Analysis
I think you two might talk about different things here. As Bekket noted, include the IR you run! If I take your test (c code), compile it to IR, and then run mem2reg, there are _no_ pointers left that could alias. (So you might want to make the example more meaningful). If I do not run mem2reg, the two stack locations that are generated for ptrA and ptrB do not alias as they are _different stack locations_. The values stored at the stack locations do however alias. I hope this helps. On 12/12, Sean Perry via llvm-dev wrote:> The variables ptra and ptrb don't actually alias. A simple way to think of > aliasing is to to say two l-values alias if assigning into one changes the > other. In your program changing the value of ptra does not change the > value of ptrb. What you do have is two pointers that point to the same > l-value. The aliasing analysis will show that variable a (which is address > taken) is aliased to a shadow of type int. Any indirections through ptra > or ptrb will use that same shadow. This is how clang and llvm get the > aliasing correct. > > This is a common mistake when learning about aliasing. People often think > the pointer should alias the object. It's really the shadow (i.e. a > pointer indirection) that aliases the object. In fact you can never have > two variables ever alasing each other. > > Regards > -- > Sean Perry > Compiler Development > IBM Canada Lab > (905)-413-6031 (tie 313-6031), fax (905)-413-4839 > > > > > From: "Артём Вопилов via llvm-dev" <llvm-dev at lists.llvm.org> > To: llvm-admin at lists.llvm.org, llvm-dev at lists.llvm.org, > mailman at lists.llvm.org, bugs-admin at lists.llvm.org > Date: 12/12/18 11:54 AM > Subject: [llvm-dev] LLVM Alias Analysis > Sent by: "llvm-dev" <llvm-dev-bounces at lists.llvm.org> > > > > Dear LLVM Developers, > > My name is Artem Vopilov, I am a student at TU Darmstadt. I am writing to > you to ask about Alias Analysis. > > I am using llvm to analyze alias between variables in programs. I am using > Alias Analysis implemented in llvm with command "opt -analyze -aa-eval > -print-all-alias-modref-info" and for printing sets of alias "opt -analyze > -aa-eval -print-alias-sets". > > I execute these commands on the small test program I attached to this > email. > If you take a look at it, it will be obvious, that variables "ptra" and > "ptrb" alias. However, the results of Alias Analysis do not indicate, that > these variable alias. I would like to ask you, if it is possible to change > the source code of Alias Analysis, so that it will show that "ptra" and > "ptrb" variables from the test program alias. > > I am looking forward to hearing from you and hope, that you can help me > solve my problem. > > Respectfully yours, > Artem Vopilov > [attachment "Test.c" deleted by Sean Perry/Toronto/IBM] > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev > > >> _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-- Johannes Doerfert Researcher Argonne National Laboratory Lemont, IL 60439, USA jdoerfert at anl.gov -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 228 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20181212/242fb80c/attachment.sig>