[llvm] [InstCombine] Missed optimization: Fold (sext(a) & c1) == c2 to (a & c3) == trunc(c2) (PR #112646)
Lee Wei via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 3 19:33:46 PST 2024
================
@@ -7716,6 +7716,32 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
if (Instruction *Res = foldReductionIdiom(I, Builder, DL))
return Res;
+ {
+ Value *A;
+ const APInt *C1, *C2;
+ ICmpInst::Predicate Pred = I.getPredicate();
+ if (ICmpInst::isEquality(Pred)) {
+ // sext(a) & c1 == c2 --> a & c3 == trunc(c2)
+ // sext(a) & c1 != c2 --> a & c3 != trunc(c2)
+ if (match(Op0, m_And(m_SExtLike(m_Value(A)), m_APInt(C1))) &&
----------------
leewei05 wrote:
You're right, `zext nneg` will get folded via other code. I'll change the match.
https://alive2.llvm.org/ce/z/7sTJH9
https://github.com/llvm/llvm-project/pull/112646
More information about the llvm-commits
mailing list