[llvm] [InstCombine] Canonicalize (a + 1 == 0) ? -1 : a + 1 -> uadd.sat(a, 1) (PR #144566)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 17 12:28:03 PDT 2025


topperc wrote:

> > I don't think this is the right place to fix this. We need to rewrite
> > ```
> >   %add = add i32 %num, 1
> >   %cmp = icmp eq i32 %add, 0
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > to
> > ```
> >   %cmp = icmp eq i32 %num, -1
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > Then the rest just works.
> > unsigned square2eer(unsigned a) {
> > return a + 7 == 7;
> > }
> 
> folds fine, but when we have multiple uses, it is not simplifying because it is reusing the a + 7

I don't understand why we're willing to fold an `ugt` compare when the add has multiple uses, but not an `eq` compare.

https://github.com/llvm/llvm-project/pull/144566


More information about the llvm-commits mailing list