SelectionDAG: Reuse bigger sized constants in memset expansion.
authorMatthias Braun <matze@braunis.de>
Tue, 23 Oct 2018 23:19:23 +0000 (23:19 +0000)
committerMatthias Braun <matze@braunis.de>
Tue, 23 Oct 2018 23:19:23 +0000 (23:19 +0000)
commit4f82406c460d7b302fed395464d6649dc6aea05e
tree9a49413b1f5ea84d3171a6c571c3af2d96a1f15f
parentd3e7675331e521e6983449c335c883879c02c5fd
SelectionDAG: Reuse bigger sized constants in memset expansion.

When implementing memset's today we often see this pattern:
$x0 = MOV 0xXYXYXYXYXYXYXYXY
store $x0, ...
$w1 = MOV 0xXYXYXYXY
store $w1, ...

We first create a 64bit constant in a 64bit register with all bytes the
same and then create a 32bit constant with all bytes the same in a 32bit
register. In many targets we could just access the lower byte of the
64bit register instead.

- Ideally this would be handled by the ConstantHoist pass but it runs
  too early when memset isn't expanded yet.
- The memset expansion code already had this optimization implemented,
  however SelectionDAG constantfolding would constantfold the
  "trunc(bigconstnat)" pattern to "smallconstant".
- This patch makes the memset expansion mark the constant as Opaque and
  stop DAGCombiner from constant folding in this situation. (Similar to
  how ConstantHoisting marks things as Opaque to avoid folding
  ADD/SUB/etc.)

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

llvm-svn: 345102
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/lib/Target/X86/X86ISelLowering.h
llvm/test/CodeGen/AArch64/arm64-memset-inline.ll
llvm/test/CodeGen/X86/pr38771.ll [deleted file]