[PATCH] D48828: [InstSimplify] fold extracting from std::pair

Hiroshi Inoue via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 2 06:03:29 PDT 2018


inouehrs created this revision.
inouehrs added reviewers: dberlin, spatel, efriedma, echristo, kbarton, nemanjai.
Herald added a subscriber: Prazek.

This patch intends to enable jump threading with a method whose return type is std::pair<int, bool> or std::pair<bool, int>
For example, jump threading does not work for the if statement in func.

  std::pair<int, bool> callee(int v) {
    int a = dummy(v);
    if (a) return std::make_pair(dummy(v), true);
    else return std::make_pair(v, v < 0);
  }
  
  int func(int v) {
    std::pair<int, bool> rc = callee(v);
    if (rc.second) {
      // do something
    }

SROA executed before the method inlining replaces std::pair by i64 without splitting in both `callee` and `func` since at this point no access to the individual fields is seen to SROA.
After inlining, jump threading fails to identify that the incoming value is a constant due to additional instructions (like or, and, trunc).

This patch add two patterns in InstructionSimplify to fold extraction of members of std::pair. 
These patterns help NewGVN pass apply phi-of-ops optimization to result in successful jump threading.
I am going to add few more patterns for wider range of targets, but I like to start with the basic patterns.

Later, in the CFG simplification pass, the similar code modification happens. But it is too late to help jump threading.

This patch replaces my old patch https://reviews.llvm.org/D44626 which do similar optimization in InstCombine as suggested by reviewers.


https://reviews.llvm.org/D48828

Files:
  lib/Analysis/InstructionSimplify.cpp
  test/Transforms/NewGVN/pair_jumpthread.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48828.153697.patch
Type: text/x-patch
Size: 7525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180702/3c1bd47e/attachment.bin>


More information about the llvm-commits mailing list