[PATCH] D154791: [InstCombine] Transform bitwise (A >> C - 1, zext(icmp)) -> zext (bitwise(A < 0, icmp)) fold.
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 10 13:05:36 PDT 2023
nikic added a comment.
This is still missing multi-use tests. We'll need some m_OneUse guards to prevent unprofitable transforms.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:1716
- // ( A << (X - 1) ) | ((A > 0) zext to iX)
- // <=> A < 0 | A > 0
- // <=> (A != 0) zext to iX
- Value *A;
- ICmpInst::Predicate Pred;
+ // fold and/or(A << X - 1, zext(icmp)) (X is the scalar bits of the type of A)
+ // -> and/or(zext(A < 0), zext(icmp))
----------------
X -> BW
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:1732-1733
- auto MatchOrZExtICmp = [&](Value *Op0, Value *Op1) -> bool {
- return match(Op0, m_LShr(m_Value(A), m_SpecificInt(Op0->getType()->getScalarSizeInBits() - 1))) &&
- match(Op1, m_ZExt(m_ICmp(Pred, m_Specific(A), m_Zero())));
+ return ZExtInst::Create(
+ ZExtInst::ZExt,
+ Builder.CreateBinOp(
----------------
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp:1742
+ if(auto *Ret = FoldBitwiseICmpZeroWithICmp(Op0, Op1)) return Ret;
+ if(auto *Ret = FoldBitwiseICmpZeroWithICmp(Op1, Op0)) return Ret;
----------------
Needs clang-format.
================
Comment at: llvm/test/Transforms/InstCombine/and-or-icmps.ll:2857
ret i32 %D
}
----------------
The main multi-use test I'm looking for is one where the resulting binop does not get folded. That's the case where your current code will increase instructions, I believe.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D154791/new/
https://reviews.llvm.org/D154791
More information about the llvm-commits
mailing list