[PATCH] D63505: [InstCombine] Fold icmp eq/ne (and %x, ~C), 0 -> %x u</u>= 0 earlier, C+1 is power of 2.

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 12:03:18 PDT 2019


lebedev.ri added inline comments.


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1656-1657
+    // ((X & ~7) == 0) --> X u< 8
+    // If X is (BinOp Y, C3), allow other rules to fold C3 with C2.
+    if (!match(X, m_c_BinOp(m_Value(), m_Constant())) &&
+        (~(*C2) + 1).isPowerOf2()) {
----------------
huihuiz wrote:
> lebedev.ri wrote:
> > Why do we care about that? Seems rather arbitrary.
> take this test as example
> 
> 
> ```
> define i1 @test_shift_and_cmp_changed2(i8 %p) {
>   %shlp = shl i8 %p, 5
>   %andp = and i8 %shlp, -64
>   %cmp = icmp ult i8 %andp, 32
>   ret i1 %cmp
> }
> 
> ```
> 
> we do miss fold for (X >> C3) & C2 != C1 --> (X & (C2 << C3)) != (C1 << C3)
Is that IR without this restriction?
We currently seem to handle it just fine https://godbolt.org/z/8DB1xD


================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1647
 
+  // Restrict these two folds to single-use 'and' (PR10267).
   if (Cmp.isEquality() && C1.isNullValue()) {
----------------
Despite how pointless it will look, please add the comment to each of the folds.
Nothing prevents from other folds being added, and this comment getting out of date.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D63505





More information about the llvm-commits mailing list