[llvm-dev] After InstCombine pass, expected output got changed

Nuno Lopes via llvm-dev llvm-dev at lists.llvm.org
Sat Aug 21 14:23:55 PDT 2021


The highlighted transformations are all correct. If there’s a bug in LLVM it’s somewhere else. But it’s more likely it’s a bug in the source program.

You can use Alive2 to check correctness of optimizations,, e.g.: https://alive2.llvm.org/ce/z/rbZbY7

 

Nuno

 

 

From: llvm-dev <llvm-dev-bounces at lists.llvm.org> On Behalf Of Rohit Aggarwal via llvm-dev
Sent: 20 August 2021 13:45
To: Florian Hahn <florian_hahn at apple.com>
Cc: llvm-dev <llvm-dev at lists.llvm.org>
Subject: Re: [llvm-dev] After InstCombine pass, expected output got changed

 

Hi Florian,

 

 

 

On Thu, Aug 19, 2021 at 3:46 PM Florian Hahn <florian_hahn at apple.com <mailto:florian_hahn at apple.com> > wrote:

 





On 19 Aug 2021, at 11:01, Rohit Aggarwal via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> > wrote:



Hi All,

 

Thanks Florian for response.

 

 Adding more details to the issue:

*	I revert the commit  [ConstantFold] Allow propagation of poison for and/or i1 <https://github.com/llvm/llvm-project/commit/2fd3037ac615643fe8058292d2b89bb19a49cb2f>  then it is working fine.
*	In this commit, a check is removed to stop the constantfold of instruction to poison value incase of integer ADD or OR instruction if either of operands are poison.
*	Using both release branch and commit reverted branch, a poison value is generated by a shift left instruction due to overflow (UB is present) 

 

Ok so it sounds like this is the reason for the different output and the transformation is correct.

    >> Yes, this poison which is generated is handled differently in llvm-trunk and reverted commit code down the pipeline. 

 

*	Now in the release branch, this poison value is propagated down to 'or' inst. and  is constantfolds %or = or  true poison  -> poison  

 

*	where as in the reverted code,  %or = or  true poison  -> true

  >> Here is the main reason, where the problem started 

*	In the release branch, the poison value propagates to its uses
*	There is a store instruction which now has a poison value
*	In visitStoreInst, store instruction got removed due to poison value
*	But in revert branch, store is not getting remove as it has defined value

See the below diff for more clarity.



 

Reattaching the  image. PFA for more clarity.

 

Thanks,

Rohit Aggarwal

 

Disclaimer:- This footer text is to convey that this email is sent by one of the users of IITH. So, do not mark it as SPAM.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210821/5518fe65/attachment.html>


More information about the llvm-dev mailing list