[PATCH] D67334: [InstCombine] fold sign-bit compares of srem

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 10 14:33:53 PDT 2019


lebedev.ri added a comment.

I'm not sure about the cases where we'd have to increase instruction count,
those may be best suited for codegen, but this patch looks good, some nits.



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:2255-2256
+                                                const APInt &C) {
+  // Match an 'is positive' or 'is negative' comparison where the remainder is
+  // a constant power-of-2 value:
+  // (X % pow2C) sgt/slt 0
----------------
Match an 'is positive' or 'is negative' comparison of remainder by a constant power-of-2 value


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:2265-2268
+  const APInt *DivisorC;
+  if (!SRem->hasOneUse() || !C.isNullValue() ||
+      !match(SRem->getOperand(1), m_Power2(DivisorC)))
+    return nullptr;
----------------
I'd maybe split this into correctness check, and one-use check, to make the comment even more obvious.


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

https://reviews.llvm.org/D67334





More information about the llvm-commits mailing list