[PATCH] D125114: [SimplifyLibCalls] handle subobjects of constant aggregates

Martin Sebor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 6 11:45:44 PDT 2022


msebor created this revision.
msebor added reviewers: spatel, MatzeB, nikic, xbolva00.
Herald added subscribers: steven.zhang, pengfei, hiraditya, kristof.beyls.
Herald added a project: All.
msebor requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This change removes the known limitation of the library function call folders to only work with top-level arrays of characters (as per the TODO comment in the code)  and allows them to also fold calls involving subobjects of constant aggregates such as member arrays.  It does that by

1. adding a new function, `ReadByteArrayFromGlobal` that returns the byte representation of the initializer of a global constant, as a `ConstantArray`, and
2. removing the restriction from `getConstantDataArrayInfo` to only consider simple strings and having it use `ReadByteArrayFromGlobal` to convert other aggregates to arrays of bytes.

This initial change only handles constant offsets into these aggregates.

I have tested the change by building LLVM on x86_64 and running `check-all`.  In full disclosure, the patch seems to cause a few surprising regressions in the test suite that I'm yet to investigate:

  LLVM :: CodeGen/AArch64/arm64-2012-05-07-MemcpyAlignBug.ll
  LLVM :: CodeGen/ARM/constantpool-promote-ldrh.ll
  LLVM :: CodeGen/BPF/remove_truncate_5.ll
  LLVM :: CodeGen/BPF/rodata_2.ll
  LLVM :: CodeGen/PowerPC/aix-vec-arg-spills-mir.ll
  LLVM :: CodeGen/PowerPC/aix-vec-arg-spills.ll
  LLVM :: DebugInfo/COFF/types-array.ll


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125114

Files:
  llvm/include/llvm/Analysis/ConstantFolding.h
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
  llvm/test/Transforms/InstCombine/memchr-5.ll
  llvm/test/Transforms/InstCombine/memcmp-3.ll
  llvm/test/Transforms/InstCombine/memrchr-5.ll
  llvm/test/Transforms/InstCombine/sprintf-2.ll
  llvm/test/Transforms/InstCombine/str-int-3.ll
  llvm/test/Transforms/InstCombine/strcmp-3.ll
  llvm/test/Transforms/InstCombine/strlen-5.ll
  llvm/test/Transforms/InstCombine/strlen-6.ll
  llvm/test/Transforms/InstCombine/strlen-7.ll
  llvm/test/Transforms/InstCombine/strlen-8.ll
  llvm/test/Transforms/InstCombine/strncmp-4.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125114.427689.patch
Type: text/x-patch
Size: 108763 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220506/f920e4e9/attachment-0001.bin>


More information about the llvm-commits mailing list