[PATCH] D112634: [InstCombine] canonicalize icmp with trunc op into mask and cmp, part 2

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 3 13:25:38 PDT 2021


spatel added a comment.

In D112634#3106893 <https://reviews.llvm.org/D112634#3106893>, @lebedev.ri wrote:

> Like i asked in mail, this really seems like something for `decomposeBitTestICmp()`.

I don't disagree, but we have 2 at least problems:

1. It doesn't cover the pair of folds that result in a non-zero constant for the new icmp.
2. It catches signbit tests that may currently get folded in the opposite direction (see inline comment), so we'll need to remove a transform.

So I'm leaning towards adding these as the first step. Reversing the existing fold could lead to regressions in IR or codegen, so that seems more risky, and I'll potentially have to chase down regressions to get that to stick.



================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp:1898-1900
   // (X & C2) == 0 -> (trunc X) >= 0
   // (X & C2) != 0 -> (trunc X) <  0
   //   iff C2 is a power of 2 and it masks the sign bit of a legal integer type.
----------------
This is an opposing transform if we use decomposeBitMask to make this patch more general.
This was added with: 
dfa3b0954145ec6



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112634/new/

https://reviews.llvm.org/D112634



More information about the llvm-commits mailing list