We can use KnownBitsAnalysis to cover cases when mask is not trivial. It can
also help with cases when mask is not constant but can still be folded into
one. Since 'and' is commutative we should treat both operands as possible
replacements.
Details
Diff Detail
Event Timeline
llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp | ||
---|---|---|
2881–2889 | Or you can implement it generally and symmetrically, so that it works for non-constants as well as constants: X & Y -> X // if (XBits.Zero | YBits.One).isAllOnesValue() X & Y -> Y // if (XBits.One | YBits.Zero).isAllOnesValue() |
LGTM modulo minor comments inline.
llvm/include/llvm/CodeGen/GlobalISel/CombinerHelper.h | ||
---|---|---|
432 | Maybe just matchRedundantAnd? | |
llvm/include/llvm/Target/GlobalISel/Combine.td | ||
385 | I think we should define a standard Register matchdata that we can use here and elsewhere. Doesn't have to be part of this patch though. |
llvm/include/llvm/Target/GlobalISel/Combine.td | ||
---|---|---|
385 | +1 |
Unnecessary whitespace change