[PATCH] D134415: [InstCombine] Improve fold icmp of truncated left shift

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 23 09:32:12 PDT 2022


spatel added a comment.

The TODO comment was actually suggesting that we handle something like this:
https://alive2.llvm.org/ce/z/dHssjh
...but this patch won't match that? If that's correct, please leave the TODO comment there.

Please add that plus any other baseline tests, so we are just showing the diffs.



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1558
+  const APInt *Z;
+  if (Cmp.isEquality() && match(X, m_Shl(m_APIntAllowUndef(Z), m_Value(Y)))) {
+    // (trunc (2**Z << Y) to iN) == 0 -> Y u>  N - Z + 1
----------------
I prefer to give a constant value some name with "C" to make it obvious that we matched a constant, so `C1` or `ShiftC` or something like that.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1559-1560
+  if (Cmp.isEquality() && match(X, m_Shl(m_APIntAllowUndef(Z), m_Value(Y)))) {
+    // (trunc (2**Z << Y) to iN) == 0 -> Y u>  N - Z + 1
+    // (trunc (2**Z << Y) to iN) != 0 -> Y u<= N - Z + 1
+    if (Z->isPowerOf2()) {
----------------
Move this comment down, so it is clear that it applies only when C == 0 - just above the C.isZero() line.
Change "Z" in the comment to match the variable name if it is changed.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134415



More information about the llvm-commits mailing list