[PATCH] D53181: SelectionDAG: Reuse bigger sized constants in memset expansion.

Matthias Braun via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 11 16:03:08 PDT 2018


MatzeB created this revision.
MatzeB added reviewers: bogner, spatel, craig.topper, RKSimon, jfb.
Herald added subscribers: eraman, mcrosier.
Herald added a reviewer: javed.absar.

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 it didn't work as DAGCombiner would fold "trunc(bigconstant)" back 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.)

rdar://44153998


Repository:
  rL LLVM

https://reviews.llvm.org/D53181

Files:
  include/llvm/CodeGen/TargetLowering.h
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  lib/Target/X86/X86ISelLowering.cpp
  lib/Target/X86/X86ISelLowering.h
  test/CodeGen/AArch64/arm64-memset-inline.ll
  test/CodeGen/X86/pr38771.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53181.169332.patch
Type: text/x-patch
Size: 7212 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181011/51800f03/attachment.bin>


More information about the llvm-commits mailing list