Charitha Saumya via llvm-dev
2021-Aug-15 01:52 UTC
[llvm-dev] Semantics of udef values in PHI instructions
Hi, Consider the following LLVM IR snippet. (also attached) the value of %unify.phi is undefined if the loop body (while.body9) is executed, otherwise it has some specific value (%c.1 is a defined value). However when I execute this IR (using lli), the value of %c.2 is always the value of %c.1, even if the loop is executed multiple times. What is the reason for this behavior? how undefined values are handled in LLVM and is this behaviour architecture dependent (depending on how undef is handled in Codegen) ? Thanks Charitha [image: Screen Shot 2021-08-14 at 9.36.28 PM.png] -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210814/dec5dd7c/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: Screen Shot 2021-08-14 at 9.36.28 PM.png Type: image/png Size: 101653 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210814/dec5dd7c/attachment-0001.png> -------------- next part -------------- A non-text attachment was scrubbed... Name: test.ll.rtf Type: text/rtf Size: 6508 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210814/dec5dd7c/attachment-0001.bin>
Nuno Lopes via llvm-dev
2021-Aug-16 10:26 UTC
[llvm-dev] Semantics of udef values in PHI instructions
Undef means it can take any value (except poison). Therefore LLVM replaces phi(undef, %x) with %x, as it can fix the value of undef. This is optimization is common and it’s not architecture dependent. This optimization is actually *wrong* in case %x is poison, as then we are replacing undef with poison for one of the predecessors (which is not correct). But LLVM is still inconsistent in the treatment of undef and we can’t fix it straight away. Nuno From: Charitha Saumya Sent: 15 August 2021 02:53 To: via Llvm-dev <llvm-dev at lists.llvm.org> Subject: [llvm-dev] Semantics of udef values in PHI instructions Hi, Consider the following LLVM IR snippet. (also attached) the value of %unify.phi is undefined if the loop body (while.body9) is executed, otherwise it has some specific value (%c.1 is a defined value). However when I execute this IR (using lli), the value of %c.2 is always the value of %c.1, even if the loop is executed multiple times. What is the reason for this behavior? how undefined values are handled in LLVM and is this behaviour architecture dependent (depending on how undef is handled in Codegen) ? Thanks Charitha -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210816/0e775129/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: image002.png Type: image/png Size: 207504 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210816/0e775129/attachment-0001.png>