[PATCH] D49362: [ThinLTO] Compute constant references

Eugene Leviant via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 16 00:09:20 PDT 2018


evgeny777 created this revision.
evgeny777 added reviewers: tejohnson, mehdi_amini.
Herald added subscribers: dexonsmith, steven_wu, eraman, inglorion.

One of annoying problems in ThinLTO is that variable promotion can prevent optimiser from constant folding/propagation. Consider
following C program

main.c

  int main() {
    int foo();
    return foo();
  }

foo.c

  #include <stdlib.h>
  
  static int gFoo = 1;
  
  int foo() {
    return gFoo;
  }
  
  void bar() {
    gFoo = rand();
  }

Note that `bar()` is dead, so variable gFoo is never really modified. However promotion of gFoo to hidden global makes it impossible for optimizer to mark it constant and fold it afterwards.

To overcome this problem I suggest to introduce concept of "constant reference" which implies all accesses to a given global from a given function are non-volatile loads. With this we can determine which variables will become read-only after DCE and convert them to constants with a special LLVM pass.

This patch implements first part of this approach. It doesn't have good test cases yet - for now I'm just interested of your opinion.


https://reviews.llvm.org/D49362

Files:
  include/llvm/Bitcode/LLVMBitCodes.h
  include/llvm/IR/ModuleSummaryIndex.h
  lib/Analysis/ModuleSummaryAnalysis.cpp
  lib/Bitcode/Reader/BitcodeReader.cpp
  lib/Bitcode/Writer/BitcodeWriter.cpp
  lib/IR/ModuleSummaryIndex.cpp
  test/ThinLTO/X86/distributed_indexes.ll
  test/ThinLTO/X86/dot-dumper.ll
  tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49362.155620.patch
Type: text/x-patch
Size: 15446 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180716/fa05870b/attachment-0001.bin>


More information about the llvm-commits mailing list