[llvm] [InstSimplify] Fold `and A, (zext (icmp eq A, 0))` into 0 (PR #66676)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 12:26:15 PDT 2023


dtcxzyw wrote:

> The general pattern here would be `zext(c) & a`, which is `c ? (a & 1) : 0`.
> 
> For the special case of `c := a == C`, if C is even then this reduces to `0`, if C is odd it reduces to `zext(c)`.
> 
> Possibly we shouldn't special case the `a == C` case though and just generally canonicalize to the select form, on which all possible folds can then be performed?
> 
> In any case, this needs to at least handle arbitrary constants.

Proof: https://alive2.llvm.org/ce/z/xVWkj3

https://github.com/llvm/llvm-project/pull/66676


More information about the llvm-commits mailing list