[PATCH] D109149: [DAG] Fold select_cc setgt X, -1, C, ~C -> xor (ashr X, BW-1), C

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 2 09:28:07 PDT 2021


spatel added inline comments.


================
Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:3905
 
+    // Fold set_cc seteq (ashr X, BW-1), -1 -> set_cc setlt X, 0
+    if (Cond == ISD::SETEQ && N0.getOpcode() == ISD::SRA &&
----------------
Split this off as its own patch? Handle the not-equal predicate too? 

We just need some tests like:

```
define i1 @src(i32 %input) {
  %sh = ashr i32 %input, 31
  %c = icmp eq i32 %sh, -1
  ret i1 %c
}

```

Note that instcombine generalizes this, so we don't care about the shift amount:
    // Canonicalize the shift into an 'and':
    // icmp eq/ne (shr X, ShAmt), C --> icmp eq/ne (and X, HiMask), (C << ShAmt)

I'm not sure if that makes sense here in codegen, but it might be worth a look to see how that changes things on various targets.


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

https://reviews.llvm.org/D109149



More information about the llvm-commits mailing list