[PATCH] D147597: [InstCombine] icmp(X | LHS, C) --> icmp(X, 0)
Jun Zhang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 12 01:52:15 PDT 2023
junaire added inline comments.
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1957
+ const APInt *LHS;
+ // icmp(X | LHS, C) --> icmp(X, 0)
+ if (C.isNonNegative() && match(Or, m_c_Or(m_Value(X), m_APInt(LHS)))) {
----------------
nikic wrote:
> Why is a constant that occurs on the RHS called LHS?
Naming is hard. `C` here should really be the `RHS` but in `foldICmpOrConstant` it's called `C` so it's kinda confusing. Maybe rename it to `RHS`?
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1958
+ // icmp(X | LHS, C) --> icmp(X, 0)
+ if (C.isNonNegative() && match(Or, m_c_Or(m_Value(X), m_APInt(LHS)))) {
+ switch (Pred) {
----------------
bcl5980 wrote:
> Do we really need c_or here? APInt should be always second operator.
Thanks, I'm uncertain if it's already been canonicalized when I first wrote this, will drop it.
================
Comment at: llvm/test/Transforms/InstCombine/icmp.ll:4633
; CHECK-LABEL: @mul_or_positive_sgt_zero(
; CHECK-NEXT: [[MUL1:%.*]] = mul i8 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i8 [[MUL1]], -1
----------------
nikic wrote:
> What's the purpose of the mul instruction in all these tests? It doesn't seem related?
Sorry, the patch has changed several times so I forgot to update the tests.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147597/new/
https://reviews.llvm.org/D147597
More information about the llvm-commits
mailing list