[PATCH] D101245: [GlobalOpt] Disable heap SROA when GEP of the only storer is used

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 24 23:31:19 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: aeubanks, evgeny777, reames.
Herald added a subscriber: hiraditya.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

heap-sra-2.ll and heap-sra-phi.ll test that we can perform SROA on a global
variable with only one storer (malloc).

The code does not consider that if a GEP of the storer is used, an arbitrary
element in the allocated array can be modified and we cannot correctly represent
it with a synthesized load of the global variable (some trivial usage e.g.
`hasAllZeroIndices` can be represented by ad-hoc code but it is clear the
optimization is worth the code complexity). For PR50027 we will get an assertion error
when creating GEP, but we could have correctness issues as well. Simply
disable the unsafe optimization.

Fix PR50027


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101245

Files:
  llvm/lib/Transforms/IPO/GlobalOpt.cpp
  llvm/test/Transforms/GlobalOpt/heap-sra-2-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-2.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-negative.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-phi-no-null-opt.ll
  llvm/test/Transforms/GlobalOpt/heap-sra-phi.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101245.340331.patch
Type: text/x-patch
Size: 4807 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210425/8d981045/attachment.bin>


More information about the llvm-commits mailing list