[PATCH] D43835: Simplify more cases of logical ops of masked icmps.

David Li via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 13 11:31:41 PDT 2018


davidxl added inline comments.


================
Comment at: lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:499
+  // For example,
+  // (icmp ne (A & 12), 0) & (icmp eq (A & 7), 1) -> (icmp eq (A & 15), 9)
+  // (icmp ne (A & 15), 0) & (icmp eq (A & 7), 0) -> (icmp eq (A & 15), 8)
----------------
yamauchi wrote:
> davidxl wrote:
> > This check can probably be extended:
> > 
> > 1) B's bitset subtracts the intersection of B and D contains only one bit
> > 2) B and D's intersection have zero values
> > 
> > In other words, D does not need to be power of 2
> Is there a chance that those two conditions you are referring to *are* what the current code is already checking here?
> 
> To be more specific, 
> 
> Isn't the condition 1 equivalent to "(B & (B ^ D)).isPowerOf2()" that the current code checks?
> 
> (I meant "(B & (B ^ D))" as the bits that are 1 in B but 0 in D.)
> 
> For example, suppose B = 1100 and D = 0101. The condition 1 would say 1100 - (1100 & 0101) = 1100 - 0100 = 1000 while (B & (B ^ D)) = (1100 & (1100 ^ 0101)) = (1100 & 1001) = 1000. 
> 
> Also, isn't the condition 2 equivalent to "((B & D) & E) == 0" that the current code checks?
> 
> (Note that in the current code, it's not D, but (B & (B ^ D)) that needs to be a power of 2.)
> 
> Do you have an example that isn't handled by the current code but is handled by the suggested extension?
You are right.  Perhaps add a comment just before the condition to document the semantics of the check.


Repository:
  rL LLVM

https://reviews.llvm.org/D43835





More information about the llvm-commits mailing list