[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 07:54:10 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()));
----------------
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;
```


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