[PATCH] D146512: [TLI] SimplifySetCC - Fold ~X s>/u< ~Y --> Y s>/u< X
Jun Zhang via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 21 05:32:43 PDT 2023
junaire marked an inline comment as done.
junaire added inline comments.
================
Comment at: llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp:4982
+ // ~X u< ~Y --> Y u< X
+ if ((Cond == ISD::SETGT || Cond == ISD::SETULE) && N0.getOpcode() == ISD::XOR &&
+ N0.getValueType().isInteger()) {
----------------
RKSimon wrote:
> Take a look at https://github.com/llvm/llvm-project/blob/3a8f161a3401edeb58e018e2d389dd2413a6417f/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp#L6501
>
> This shows its safe to handle all icmp predicates - and handles cases where one operand is a constant which can be constant folded
Thanks for the review! However, I'm unsure what is the right way to say 'all icmp predicates' and I'm worried about why vectors don't fold correctly.
If I run `llc -mcpu=btver2 test.ll` to:
```define <2 x i64> @cmp_sgt_not(<2 x i64> %a, <2 x i64> %b) { %na = xor <2 x i64> %a, <i64 -1, i64 -1> %nb = xor <2 x i64> %b, <i64 -1, i64 -1> %c = icmp sgt <2 x i64> %na, %nb %r = sext <2 x i1> %c to <2 x i64> ret <2 x i64> %r }
```
It does fold to:
```
vpcmpgtq %xmm0, %xmm1, %xmm0 retq
```
But for `ule` it doesn't work as well.
Let me know if you think it's necessary to add more tests for the remaining preds!
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146512/new/
https://reviews.llvm.org/D146512
More information about the llvm-commits
mailing list