[PATCH] D109149: [DAG] Fold select_cc setgt X, -1, C, ~C -> xor (ashr X, BW-1), C
Dave Green via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 2 05:28:46 PDT 2021
dmgreen created this revision.
dmgreen added reviewers: spatel, efriedma, RKSimon, arsenm, craig.topper.
Herald added subscribers: frasercrmck, ecnelises, kerbowa, luismarques, apazos, sameer.abuasal, pengfei, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya, tpr, nhaehnle, jvesely, nemanjai.
dmgreen requested review of this revision.
Herald added subscribers: MaskRay, wdng.
Herald added a project: LLVM.
Given a select_cc producing a constant and a negation of the constant for a comparison more than zero, we can produce an xor with ashr instead, which produces smaller code. The ashr either sets all bits or clear all bits depending on if the value is negative. This is then xor'd with the constant to optionally negate the value.
https://alive2.llvm.org/ce/z/DTFaBZ
To prevent some AMDGPU regressions, a fold for `select_cc seteq (ashr X, BW-1), -1, A, B` -> `select_cc setlt X, 0, A, B` was also added, which could be produced from xor -1 not instructions.
https://reviews.llvm.org/D109149
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/AArch64/select-constant-xor.ll
llvm/test/CodeGen/AMDGPU/fp_to_sint.ll
llvm/test/CodeGen/AMDGPU/fp_to_uint.ll
llvm/test/CodeGen/AMDGPU/select-constant-xor.ll
llvm/test/CodeGen/AMDGPU/selectcc-icmp-select-float.ll
llvm/test/CodeGen/ARM/select-constant-xor.ll
llvm/test/CodeGen/PowerPC/select-constant-xor.ll
llvm/test/CodeGen/PowerPC/smulfixsat.ll
llvm/test/CodeGen/PowerPC/testComparesi32ltu.ll
llvm/test/CodeGen/RISCV/select-constant-xor.ll
llvm/test/CodeGen/X86/pr16031.ll
llvm/test/CodeGen/X86/select-constant-xor.ll
llvm/test/CodeGen/X86/smul_fix_sat.ll
llvm/test/CodeGen/X86/sshl_sat.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109149.370227.patch
Type: text/x-patch
Size: 50627 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210902/3b7f90a6/attachment.bin>
More information about the llvm-commits
mailing list