[PATCH] D128790: [InstCombine] improve fold for icmp_eq_and to icmp_ult

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 4 12:35:32 PDT 2022


spatel accepted this revision.
spatel added a comment.
This revision is now accepted and ready to land.

LGTM



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1780
+    KnownBits Know = computeKnownBits(And->getOperand(0), 0, And);
+    // Set high zero of C2, that is friendly to the folding later.
+    NewC2 = *C2 + APInt::getHighBitsSet(C2->getBitWidth(),
----------------
Make this comment more exact:
  // Set high zeros of C2 to allow matching negated power-of-2.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1786
     // ((%x & C) == 0) --> %x u< (-C)  iff (-C) is power of two.
-    if ((~(*C2) + 1).isPowerOf2()) {
-      Constant *NegBOC =
-          ConstantExpr::getNeg(cast<Constant>(And->getOperand(1)));
+    if ((~(NewC2) + 1).isPowerOf2()) {
+      Constant *NegBOC = ConstantInt::get(And->getType(), -NewC2);
----------------
I think this should be updated to use `isNegatedPowerOf2` - if that's correct, you could even commit that change as a NFC patch before this one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128790



More information about the llvm-commits mailing list