[llvm] [InstCombine] Missed optimization: Fold (sext(a) & c1) == c2 to (a & c3) == trunc(c2) (PR #112646)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 3 13:02:34 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))) &&
----------------
nikic wrote:
If m_SExtLike doing anything here? I'd expect that if this is a zext nneg this will already get folded via other code. (If it *is* doing anything, there should be a test that demonstrates that.)
https://github.com/llvm/llvm-project/pull/112646
More information about the llvm-commits
mailing list