[PATCH] D65046: [InstCombine] Fold "x ?% y ==/!= 0" to "x & (y-1) ==/!= 0" iff y is power-of-two

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 29 13:57:06 PDT 2019


lebedev.ri marked 2 inline comments as done.
lebedev.ri added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1335
+    return nullptr;
+  // This may increase instruction count, we don't enforce that Y is a constant.
+  Value *Mask = Builder.CreateAdd(Y, Constant::getAllOnesValue(Y->getType()));
----------------
lebedev.ri wrote:
> RKSimon wrote:
> > lebedev.ri wrote:
> > > RKSimon wrote:
> > > > Do we need a ICmpInst::isEquality(Pred) test?
> > > This is valid both for equality and all unsigned predicates: https://rise4fun.com/Alive/wp0N
> > > But not signed ones: https://rise4fun.com/Alive/I67
> > > 
> > > Regardless, see beginning of the function:
> > > ```
> > >   // This fold is only valid for equality predicates.
> > >   if (!I.isEquality())
> > >     return nullptr;
> > > ```
> > Cheers - I missed that - maybe add a TODO that other unsigned predicates could be supported?
> No need: https://godbolt.org/z/XmWERN
Err, to rephrase: we don't really care about non-equality predicates here,
because the unsigned comparisons with zero will either be constant-folded,
or the predicate will be changed to an equality before we get here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D65046





More information about the llvm-commits mailing list