[llvm-dev] Semantics of udef values in PHI instructions

Nuno Lopes via llvm-dev llvm-dev at lists.llvm.org
Mon Aug 16 03:26:35 PDT 2021


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>


More information about the llvm-dev mailing list