[PATCH] D100095: [InstCombine] Conditionally emitting nsw/nuw flags when combining two add operations

Mehrnoosh Heidarpour via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 12 07:32:54 PDT 2021


MehrHeidar planned changes to this revision.
MehrHeidar added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:3911
+                C, C3, "", BO1->hasNoUnsignedWrap(), BO1->hasNoSignedWrap());
             return new ICmpInst(Pred, A, NewAdd);
           }
----------------
MehrHeidar wrote:
> MehrHeidar wrote:
> > nikic wrote:
> > > I don't think the nuw preservation is correct if the numbers are negative. Consider this case: https://alive2.llvm.org/ce/z/r3s3bw
> > I guess that if I change the condition for emitting `nuw` as follows:
> > 
> > ```
> > C3.isPositive() && BO1->hasNoUnsignedWrap()
> > ```
> > the preservation for `nuw`  will be correct.  Will it satisfy all the cases? 
> > 
> > I guess that if I change the condition for emitting `nuw` as follows:
> > 
> > ```
> > C3.isNegative() && BO1->hasNoUnsignedWrap()
> > ```
> > the preservation for `nuw`  will be correct.  Will it satisfy all the cases? 
> > 
> 
> 
I guess that if I change the condition for emitting `nuw` as follows:

```
!C3.isNegative() && BO1->hasNoUnsignedWrap()

```
the preservation for `nuw` will be correct. Will it satisfy all the cases?



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D100095/new/

https://reviews.llvm.org/D100095



More information about the llvm-commits mailing list