OSDN Git Service

[InstSimplify] fold extracting from std::pair (1/2)
authorHiroshi Inoue <inouehrs@jp.ibm.com>
Wed, 1 Aug 2018 04:40:32 +0000 (04:40 +0000)
committerHiroshi Inoue <inouehrs@jp.ibm.com>
Wed, 1 Aug 2018 04:40:32 +0000 (04:40 +0000)
commitd967b3d2e7f70adb3702ecf0ab43cf2f0a53fc12
tree995656b966392580001d86a6dfe7945cf575e485
parentc8a8300f9aba252499f14e3c0b79ac2853925962
[InstSimplify] fold extracting from std::pair (1/2)

This patch intends to enable jump threading when a method whose return type is std::pair<int, bool> or std::pair<bool, int> is inlined.
For example, jump threading does not happen 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 series of patch add patterns in InstructionSimplify to fold extraction of members of std::pair. To help jump threading, actually we need to optimize the code sequence spanning multiple BBs.
These patches does not handle phi by itself, but these additional patterns help NewGVN pass, which calls instsimplify to check opportunities for simplifying instructions over phi, apply phi-of-ops optimization to result in successful jump threading.
SimplifyDemandedBits in InstCombine, can do more general optimization but this patch aims to provide opportunities for other optimizers by supporting a simple but common case in InstSimplify.

This first patch in the series handles code sequences that merges two values using shl and or and then extracts one value using lshr.

Differential Revision: https://reviews.llvm.org/D48828

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@338485 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/shift.ll