]> granicus.if.org Git - llvm/commit
[x86] transform vector inc/dec to use -1 constant (PR33483)
authorSanjay Patel <spatel@rotateright.com>
Mon, 26 Jun 2017 14:19:26 +0000 (14:19 +0000)
committerSanjay Patel <spatel@rotateright.com>
Mon, 26 Jun 2017 14:19:26 +0000 (14:19 +0000)
commit8bfecccf46baf4d31a4b4277ffec56e635c74f56
tree8529f3d4e2cf932c58335a43fb0e1fa1ad8b3b55
parentca59b915b5dc9ffec44588acf4b1bdc35944956f
[x86] transform vector inc/dec to use -1 constant (PR33483)

Convert vector increment or decrement to sub/add with an all-ones constant:

add X, <1, 1...> --> sub X, <-1, -1...>
sub X, <1, 1...> --> add X, <-1, -1...>

The all-ones vector constant can be materialized using a pcmpeq instruction that is
commonly recognized as an idiom (has no register dependency), so that's better than
loading a splat 1 constant.

AVX512 uses 'vpternlogd' for 512-bit vectors because there is apparently no better
way to produce 512 one-bits.

The general advantages of this lowering are:
1. pcmpeq has lower latency than a memop on every uarch I looked at in Agner's tables,
   so in theory, this could be better for perf, but...

2. That seems unlikely to affect any OOO implementation, and I can't measure any real
   perf difference from this transform on Haswell or Jaguar, but...

3. It doesn't look like it from the diffs, but this is an overall size win because we
   eliminate 16 - 64 constant bytes in the case of a vector load. If we're broadcasting
   a scalar load (which might itself be a bug), then we're replacing a scalar constant
   load + broadcast with a single cheap op, so that should always be smaller/better too.

4. This makes the DAG/isel output more consistent - we use pcmpeq already for padd x, -1
   and psub x, -1, so we should use that form for +1 too because we can. If there's some
   reason to favor a constant load on some CPU, let's make the reverse transform for all
   of these cases (either here in the DAG or in a later machine pass).

This should fix:
https://bugs.llvm.org/show_bug.cgi?id=33483

Differential Revision: https://reviews.llvm.org/D34336

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306289 91177308-0d34-0410-b5e6-96231b3b80d8
21 files changed:
lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/avg.ll
test/CodeGen/X86/avx-intrinsics-x86-upgrade.ll
test/CodeGen/X86/avx-intrinsics-x86.ll
test/CodeGen/X86/avx-logic.ll
test/CodeGen/X86/avx-vperm2x128.ll
test/CodeGen/X86/avx2-intrinsics-x86-upgrade.ll
test/CodeGen/X86/avx2-logic.ll
test/CodeGen/X86/select.ll
test/CodeGen/X86/sse2-intrinsics-x86-upgrade.ll
test/CodeGen/X86/vec_ctbits.ll
test/CodeGen/X86/vector-tzcnt-128.ll
test/CodeGen/X86/vector-tzcnt-256.ll
test/CodeGen/X86/vector-tzcnt-512.ll
test/CodeGen/X86/widen_arith-1.ll
test/CodeGen/X86/widen_arith-2.ll
test/CodeGen/X86/widen_arith-3.ll
test/CodeGen/X86/widen_cast-2.ll
test/CodeGen/X86/widen_cast-3.ll
test/CodeGen/X86/widen_cast-4.ll
test/CodeGen/X86/widen_conv-1.ll